有人可以给我一个使用 SSHJ 进行公钥身份验证的示例吗?我意识到这个问题本质上与 ssh example of private/public key authentication 相同,然而作者的回答https://stackoverflow.com/users/126346/shikhar指的是一个不再存在的谷歌用户组,我无法让它工作。
谢谢! 菲尔
最佳答案
我们构建了 overthere framework在 SSHJ 之上。哪个可以连接也可以使用 key 文件连接。 以下代码应该可以工作,但请确保将 bouncycaSTLe 库添加到类路径中。
SSHClient client = new SSHClient();
String username = "johndoe";
File privateKey = new File("~/.ssh/id_rsa");
KeyProvider keys = client.loadKeys(privateKey.getPath());
client.authPublickey(username, keys);
希望对您有所帮助。
关于java - 来自文件的公钥验证的 SSHJ 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7580083/