我希望能够使用JSch Java SSH库连接到我的EC2实例.如何在AWS中使用AWS的.pem密钥对?尝试连接时如何处理UnknownHostKey错误?
在sshj命令行相当于什么,
ssh -i /path/to/mykey.private username@host
Run Code Online (Sandbox Code Playgroud)
我试过(省略错误处理),
final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("host");
ssh.authPublickey("username", "/path/to/mykey.private");
final Session session = ssh.startSession();
...
Run Code Online (Sandbox Code Playgroud)
但在我看到的日志声明中,
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
Run Code Online (Sandbox Code Playgroud)
谢谢,埃弗雷特
我想创建一个Java应用程序,用ssh连接到我的远程Linux服务器.有人可以在eclipse中向我发送一些文档或教程以开始使用sshj(我在Windows环境中工作).
第一次询问stackoverflow,还使用sshj.除了sshj提供的示例之外,我还没有找到任何帮助使用此API的好资源.
我一直在尝试使用sshj进行远程端口转发,并遇到了这个错误.
Exception in thread "main" net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods
Run Code Online (Sandbox Code Playgroud)
我用VM测试了auth,但没有使用公钥.我将使用它连接到我知道登录的EC2实例.
public void startRemotePortForwardingConnection(LocalPortForwarder.Parameters parameters) throws IOException{
sshClient.connect(parameters.getLocalHost());
this.connectionStatus = CONNECTED;
System.out.print("Connected to localhost" + NEWLINE);
try {
sshClient.authPassword(this.username, this.password);
System.out.print("Authorized with as user " + username + " with password " + password + NEWLINE);
// the local port we should be listening on
RemotePortForwarder.Forward localPortToListenOn = new RemotePortForwarder.Forward(parameters.getLocalPort());
System.out.print("localPortToListenOn initialized" + NEWLINE);
// where we should forward the packets
InetSocketAddress socketAddress = new InetSocketAddress(parameters.getRemoteHost(), parameters.getRemotePort());
SocketForwardingConnectListener remotePortToForwardTo …Run Code Online (Sandbox Code Playgroud)