2013-04-04 52 views
5

第一次問的計算器,以及使用sshj。除了sshj提供的例子之外,我還沒有找到任何好的資源來幫助使用這個API。net.schmizz.sshj.userauth.UserAuthException:用盡可用的驗證方法

我一直在嘗試使用sshj進行遠程端口轉發,並已運行到這個錯誤。

Exception in thread "main" net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods 

我使用虛擬機測試了身份驗證,但未使用公鑰。我將使用它來連接到我知道登錄的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 = new SocketForwardingConnectListener(socketAddress); 
     System.out.print("remotePortToForwardTo initialized" + NEWLINE); 

     //bind the forwarder to the correct ports 
     sshClient.getRemotePortForwarder().bind(localPortToListenOn, remotePortToForwardTo); 
     System.out.print("ports bound together" + NEWLINE); 

     sshClient.getTransport().setHeartbeatInterval(30); 
     sshClient.getTransport().join(); 
    } 
    finally { 
     sshClient.disconnect(); 
    } 
} 

可能不是最好的(或者甚至是正確的)方式來做到這一點。

+0

的可能的複製[SSHJ - 密鑰對登錄到EC2實例(HTTP://計算器.COM /問題/ 9283556/sshj-密鑰對登錄到EC2實例) – Pureferret 2016-09-22 13:38:26

回答