SSHJ Example of Public Key Auth from File

ぃ、小莉子 提交于 2019-11-30 20:46:57
Hiery Nomus

We built the overthere framework on top of SSHJ. Which can connect also connect using key files. The following piece of code should work, but make sure you add the bouncycastle library to your classpath.

SSHClient client = new SSHClient();
String username = "johndoe";
File privateKey = new File("~/.ssh/id_rsa");
KeyProvider keys = client.loadKeys(privateKey.getPath());
client.authPublickey(username, keys);

Hope that helps.

I just had this issue as well. I ended up changing

client.authPublickey(user, "id_rsa.pub")

to

client.authPublickey(user, client.loadKeys("id_rsa"))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!