[英]Apache SSHD client: authenticate with identity file
I am trying to write an SSH client using MINA SSHD, connecting with an identity file generated by openSSH ( id_rsa
and the corresponding public key id_rsa.pub
)我正在尝试使用 MINA SSHD 编写 SSH 客户端,连接由 openSSH 生成的身份文件(
id_rsa
和相应的公钥id_rsa.pub
)
The docs say to write something along these lines: 文档说要按照这些思路写一些东西:
SshClient client = SshClient.setUpDefaultClient();
client.start();
// using the client for multiple sessions...
try (ClientSession session = client.connect(user, host, port)
.verify(1000)
.getSession()) {
session.addPublicKeyIdentity(/* ...key-pair... */);
session.auth().verify(1000);
// ...
}
client.stop();
How do I build the argument to the method addPublicKeyIdentity
?如何构建方法
addPublicKeyIdentity
的参数? How do I convert my identity file to a KeyPair
?如何将我的身份文件转换为
KeyPair
?
Many thanks非常感谢
You may try to use org.apache.sshd.common.keyprovider.FileKeyPairProvider
instead.您可以尝试改用
org.apache.sshd.common.keyprovider.FileKeyPairProvider
。
Example:例子:
FileKeyPairProvider provider = new FileKeyPairProvider(/*Path to your privateKey*/);
provider.setPasswordFinder(FilePasswordProvider.of(/*your private key passphrase*/));
session.setKeyIdentityProvider(provider);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.