Find also custom user named private keys in ~/.ssh
- Dominant language
- Java
- Stars
- 2.7k
- Forks
- 620
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 11
Description
SSHJ by default finds only private keys named:
- id_rsa
- id_dsa
- id_ed25519
- id_ecdsa
It would be nice if it would also pick up user named private keys. This allows us to share code.
I wrote the following code (sorry for the Kotlin):
```
private fun authWithSSHKey(username: String, sshClient: SSHClient)
{
val userSSHConfigFolder = Paths.get(System.getProperty("user.home")).resolve(".ssh")
val list = Files.list(userSSHConfigFolder)
val privateKeyFiles = arrayListOf()
for (path in list)
{
if (Files.isRegularFile(path)
&& path.fileName.toString() != "config"
&& path.fileName.toString() != "known_hosts"
&& !path.fileName.toString().endsWith(".pub"))
{
val absoluteNormalizedString = path.toAbsolutePath().normalize().toString()
privateKeyFiles.add(absoluteNormalizedString)
}
}
sshClient.authPublickey(username, *privateKeyFiles.toTypedArray())
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.