SSHJ文件公钥验证示例 [英] SSHJ Example of Public Key Auth from File

查看:234
本文介绍了SSHJ文件公钥验证示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能举例说明使用SSHJ进行公钥认证吗?我意识到这个问题与私有/公钥认证的ssh示例基本相同,但作者的答案 https://stackoverflow.com/users/126346/shikhar 指的是谷歌不再存在的用户组,我无法让它工作。

Can someone give me an example of using SSHJ for Public Key Authentication? I realise this question is essentially identical to ssh example of private/public key authentication, however the answer by the author https://stackoverflow.com/users/126346/shikhar refers to a google user group that no longer exists, and I am having trouble getting it to work.

谢谢!
Phil

Thanks! Phil

推荐答案

我们建立了覆盖框架。哪个可以连接也使用密钥文件连接。
以下代码应该可以使用,但请确保将bouncycastle库添加到类路径中。

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);

希望有所帮助。

这篇关于SSHJ文件公钥验证示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆