I am on a Windows machine and I need to write Java code that connects to a remote Solaris machine using SSH, and then can execute commands on it and get their output, but I have some authentication issues. (I am using SSHJ 0.8.1)
Here is the code to connect and start the session:
public void init(String address, int portNumber, String hostKeyVerifier) throws IOException { client = new SSHClient(); client.getConnection().setTimeout(300); client.addHostKeyVerifier(hostKeyVerifier); client.connect(address, portNumber); client.authPassword("user", "password"); session = client.startSession(); }
I expect this to lead to a working connection, as an attempt to connect to Apache Karaf instances with the same code works (albeit with a different host key verifier, address, port and credentials). Instead, this is the result that I get:
16:27:58.029 [main] INFO n.schmizz.sshj.common.SecurityUtils - BouncyCastle not registered, using the default JCE provider 16:27:58.159 [main] INFO nssshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_8_1_SNAPSHOT 16:27:58.159 [main] INFO nssshj.transport.TransportImpl - Server identity string: SSH-2.0-Sun_SSH_2.2 16:27:58.159 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<kex done>> to `null` 16:27:58.159 [main] DEBUG nssshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT 16:27:58.169 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<kexinit sent>> to `SOME` 16:27:58.169 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<kex done>> 16:27:58.189 [reader] DEBUG nssshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT 16:27:58.189 [reader] DEBUG nssshj.transport.KeyExchanger - Negotiated algorithms: [ kex=diffie-hellman-group1-sha1; sig=ssh-rsa; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha1; s2cMAC=hmac-sha1; c2sComp=none; s2cComp=none ] 16:27:58.209 [reader] DEBUG net.schmizz.sshj.transport.kex.DHG1 - Sending SSH_MSG_KEXDH_INIT 16:27:58.239 [reader] DEBUG nssshj.transport.KeyExchanger - Received kex followup data 16:27:58.239 [reader] DEBUG net.schmizz.sshj.transport.kex.DHG1 - Received SSH_MSG_KEXDH_REPLY 16:27:58.249 [reader] DEBUG nssshj.transport.KeyExchanger - Trying to verify host key with net.schmizz.sshj.SSHClient$1@135bdd3 16:27:58.249 [reader] DEBUG nssshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS 16:27:58.249 [reader] DEBUG nssshj.transport.KeyExchanger - Received SSH_MSG_NEWKEYS 16:27:58.249 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<kexinit sent>> to `null` 16:27:58.249 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<kex done>> to `SOME` 16:27:58.249 [main] DEBUG net.schmizz.sshj.SSHClient - Key exchange took 0.09 seconds 16:27:58.249 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<service accept>> to `null` 16:27:58.249 [main] DEBUG nssshj.transport.TransportImpl - Sending SSH_MSG_SERVICE_REQUEST for ssh-userauth 16:27:58.249 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<service accept>> 16:27:58.309 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<service accept>> to `SOME` 16:27:58.309 [main] DEBUG nssshj.transport.TransportImpl - Setting active service to ssh-userauth 16:27:58.309 [main] DEBUG n.schmizz.sshj.userauth.UserAuthImpl - Trying `password` auth... 16:27:58.309 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<authenticated>> to `null` 16:27:58.309 [main] DEBUG nssuserauth.method.AuthPassword - Requesting password for [AccountResource] kc@10.82.82.6 16:27:58.309 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<authenticated>> 16:28:28.320 [main] DEBUG n.schmizz.sshj.userauth.UserAuthImpl - `password` auth failed 16:28:28.320 [main] DEBUG n.schmizz.sshj.userauth.UserAuthImpl - Saving for later - net.schmizz.sshj.userauth.UserAuthException: Timeout expired 16:28:28.320 [main] DEBUG n.schmizz.sshj.userauth.UserAuthImpl - Trying `keyboard-interactive` auth... 16:28:28.321 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<authenticated>> to `null` 16:28:28.321 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<authenticated>> 16:28:43.363 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<authenticated>> to `SOME` 16:28:43.363 [main] DEBUG n.schmizz.sshj.userauth.UserAuthImpl - `keyboard-interactive` auth successful 16:28:43.365 [main] DEBUG nssshj.transport.TransportImpl - Setting active service to ssh-connection 16:28:43.366 [main] DEBUG nssshj.connection.ConnectionImpl - Attaching `session` channel (
Also, this is the stack trace I get in Eclipse:
net.schmizz.sshj.connection.ConnectionException: Unexpected: SSH_MSG_UNIMPLEMENTED at net.schmizz.sshj.connection.ConnectionException$1.chain(ConnectionException.java:32) at net.schmizz.sshj.connection.ConnectionException$1.chain(ConnectionException.java:26) at net.schmizz.concurrent.Promise.deliverError(Promise.java:95) at net.schmizz.concurrent.Event.deliverError(Event.java:72) at net.schmizz.concurrent.ErrorDeliveryUtil.alertEvents(ErrorDeliveryUtil.java:34) at net.schmizz.sshj.connection.channel.AbstractChannel.notifyError(AbstractChannel.java:241) at net.schmizz.sshj.connection.channel.direct.SessionChannel.notifyError(SessionChannel.java:249) at net.schmizz.sshj.common.ErrorNotifiable$Util.alertAll(ErrorNotifiable.java:35) at net.schmizz.sshj.connection.ConnectionImpl.notifyError(ConnectionImpl.java:250) at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:578) at net.schmizz.sshj.transport.Reader.run(Reader.java:79) Caused by: net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED at net.schmizz.sshj.AbstractService.notifyUnimplemented(AbstractService.java:66) at net.schmizz.sshj.transport.TransportImpl.gotUnimplemented(TransportImpl.java:555) at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:490) at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127) at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195) at net.schmizz.sshj.transport.Reader.run(Reader.java:72)
PuTTY is able to connect to the same address and port using the same credentials without any problems, although it does take some time. What do I need to do to get a working Java connection here?
source share