私钥/公钥认证的 ssh 示例 [英] ssh example of private/public key authentication

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

问题描述

谁能给我一个 sshj 中的私钥/公钥身份验证示例?

Can anyone give me an example of private/public key authentication in sshj?

在 sshj 中,命令行相当于什么,

In sshj what's the command line equivalent of,

ssh -i /path/to/mykey.private username@host

我试过了(省略了错误处理),

I tried (error handling omitted),

final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("host");
ssh.authPublickey("username", "/path/to/mykey.private");
final Session session = ssh.startSession();
...

但在我看到的日志语句中,

but in the log statements I see,

DEBUG net.schmizz.sshj.SSHClient - Attempting to load key from: /path/to/mykey.private
WARN  net.schmizz.sshj.SSHClient - Could not load keys due to: {}
net.schmizz.sshj.common.SSHException: No provider available forUnknown key file
    at net.schmizz.sshj.SSHClient.loadKeys(SSHClient.java:482) ~[sshj-0.3.0.jar:na]
...
Exception in thread "main" 10:49:55.943 [reader] DEBUG
net.schmizz.sshj.transport.Reader - Stopping
net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods

谢谢,埃弗里特

推荐答案

您需要为大多数键类型包含 BouncyCastle 库.这是Maven依赖项:org.bouncycastlebcprov-jdk161.46

You need to include BouncyCastle lib for most key types. Here's the Maven dependency: org.bouncycastle bcprov-jdk16 1.46

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

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