for the first time by querying stackoverflow as well as using sshj. Other than the examples provided with sshj, I really did not find any good resources to help use this API.
I am trying to perform remote port forwarding using sshj and encountered this error.
Exception in thread "main" net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods
I tested auth with a VM, but without using a public key. I would use this to connect to an EC2 instance on which I know the 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);
RemotePortForwarder.Forward localPortToListenOn = new RemotePortForwarder.Forward(parameters.getLocalPort());
System.out.print("localPortToListenOn initialized" + NEWLINE);
InetSocketAddress socketAddress = new InetSocketAddress(parameters.getRemoteHost(), parameters.getRemotePort());
SocketForwardingConnectListener remotePortToForwardTo = new SocketForwardingConnectListener(socketAddress);
System.out.print("remotePortToForwardTo initialized" + NEWLINE);
sshClient.getRemotePortForwarder().bind(localPortToListenOn, remotePortToForwardTo);
System.out.print("ports bound together" + NEWLINE);
sshClient.getTransport().setHeartbeatInterval(30);
sshClient.getTransport().join();
}
finally {
sshClient.disconnect();
}
}
This may not be the best (or even right) way to do this.
source
share