尝试启动会话的SSHJ会导致SSH_MSG_UNIMPLEMENTED

时间:2014-12-15 14:52:51

标签: java ssh sshj

我在Windows机器上,我需要编写一些使用SSH连接到远程Solaris机器的Java代码,然后可以在其上执行命令并获取其输出,但我有有些麻烦认证。 (我使用SSHJ 0.8.1)

这是连接和启动会话的代码:

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();
   }

我希望这会导致工作连接,因为尝试使用相同的代码(虽然使用不同的主机密钥验证程序,地址,端口和凭据)连接到Apache Karaf的实例。相反,这是我得到的输出:

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  n.s.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_8_1_SNAPSHOT
16:27:58.159 [main] INFO  n.s.sshj.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 n.s.sshj.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 n.s.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
16:27:58.189 [reader] DEBUG n.s.sshj.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 n.s.sshj.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 n.s.sshj.transport.KeyExchanger - Trying to verify host key with net.schmizz.sshj.SSHClient$1@135bdd3
16:27:58.249 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS
16:27:58.249 [reader] DEBUG n.s.sshj.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 n.s.sshj.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 n.s.sshj.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 n.s.s.userauth.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 n.s.sshj.transport.TransportImpl - Setting active service to ssh-connection
16:28:43.366 [main] DEBUG n.s.sshj.connection.ConnectionImpl - Attaching `session` channel (#0)
16:28:43.366 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<chan#0 / open>>
16:29:28.387 [reader] DEBUG n.s.sshj.transport.TransportImpl - Received SSH_MSG_UNIMPLEMENTED #5
16:29:28.397 [reader] ERROR n.s.sshj.transport.TransportImpl - Dying because - net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED
16:29:28.397 [reader] INFO  n.s.sshj.transport.TransportImpl - Disconnected - PROTOCOL_ERROR
16:29:28.398 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Got notified of net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED
16:29:28.398 [reader] DEBUG n.s.sshj.connection.ConnectionImpl - Notified of net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED
16:29:28.398 [reader] DEBUG n.s.s.c.c.direct.SessionChannel - Channel #0 got notified of net.schmizz.sshj.common.SSHException: [PROTOCOL_ERROR] Unexpected: SSH_MSG_UNIMPLEMENTED
16:29:28.398 [reader] DEBUG n.s.sshj.connection.ConnectionImpl - Forgetting `session` channel (#0)
16:29:28.398 [main] ERROR net.schmizz.concurrent.Promise - <<chan#0 / open>> woke to: net.schmizz.sshj.connection.ConnectionException: Unexpected: SSH_MSG_UNIMPLEMENTED
16:29:28.398 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#0 / close>> to `SOME`
16:29:28.398 [reader] DEBUG n.s.sshj.transport.TransportImpl - Setting active service to null-service
16:29:28.398 [reader] DEBUG n.s.sshj.transport.TransportImpl - Sending SSH_MSG_DISCONNECT: reason=[PROTOCOL_ERROR], msg=[Unexpected: SSH_MSG_UNIMPLEMENTED]
16:29:28.398 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<transport close>> to `SOME`
16:29:28.398 [reader] DEBUG net.schmizz.sshj.transport.Reader - Stopping

此外,这是我在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能够使用相同的凭据连接到同一地址和端口,没有任何问题,但确实需要一些时间。我该怎么做才能在这里与Java建立有效的连接?

0 个答案:

没有答案