prima richiesta su StackOverflow e anche con sshj. Oltre agli esempi forniti con sshj, non ho trovato alcuna buona risorsa per aiutare a usare questa API.net.schmizz.sshj.userauth.UserAuthException: Exhausted metodi di autenticazione disponibili
Ho cercato di eseguire il port forwarding remoto usando sshj e ho incontrato questo errore.
Exception in thread "main" net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods
Ho testato l'autenticazione con una macchina virtuale, ma senza utilizzare una chiave pubblica. Lo userei per connettermi a un'istanza EC2 su cui conosco il login.
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();
}
}
Probabilmente non è il modo migliore (o anche giusto) per farlo.
Possibile duplicato di [SSHJ - coppia di chiavi di accesso alla istanza EC2] (http: // StackOverflow .com/domande/9283556/sshj-coppia di chiavi-login-per-EC2-esempio) – Pureferret