net.schmizz.sshj.transport.TransportException:无法达成和解

时间:2014-07-01 21:21:41

标签: java sshj

我正在尝试使用SSHJ将ssh写入其他计算机。下面的PFA代码(不包括try / catch / finally块)。

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
final SSHClient sshClient = new SSHClient();
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
sshClient.connect("test-hostname");
sshClient.authPublickey("test-user", private_key_path);
Session session = sshClient.startSession();
Session.Command cmd = session.exec(TEST_SSH_COMMAND);
cmd.join(5, TimeUnit.SECONDS);
if(cmd.getExitStatus() == 0) {
   System.out.println("Success");
}

当我尝试执行上述程序时,我收到以下错误

[reader] n.s.sshj.transport.TransportImpl - Dying because -net.schmizz.sshj.transport.TransportException: Unable to reach a settlement: [] and [aes128-ctr, aes192-ctr, aes256-ctr, arcfour256, arcfour128, aes128-cbc, 3des-cbc, blowfish-cbc, cast128-cbc, aes192-cbc, aes256-cbc, arcfour, rijndael-cbc@lysator.liu.se]
2014-07-01 20:45:09,021 INFO  [reader] n.s.sshj.transport.TransportImpl - Disconnected - UNKNOWN
2014-07-01 20:45:09,023 ERROR [pool-3-thread-1] net.schmizz.concurrent.Promise - <<kex done>> woke to: net.schmizz.sshj.transport.TransportException: Unable to reach a settlement: [] and [aes128-ctr, aes192-ctr, aes256-ctr, arcfour256, arcfour128, aes128-cbc, 3des-cbc, blowfish-cbc, cast128-cbc, aes192-cbc, aes256-cbc, arcfour, rijndael-cbc@lysator.liu.se]

2014-07-01 20:45:09,024 INFO [pool-3-thread-1] n.s.sshj.transport.TransportImpl - Disconnected - BY_APPLICATION

有人可以帮我调试问题。

感谢。

3 个答案:

答案 0 :(得分:0)

我无法找到解决此问题的任何方法。相反,我开始使用JSch,现在工作正常。

java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");

Session session = null;
ChannelExec channel = null;

    try {
            JSch jSch = new JSch();
            jSch.addIdentity("/tmp/privatekey");

            session = jSch.getSession("testuser", address, 22);
            session.setConfig(config);
            session.connect();

            channel = (ChannelExec) session.openChannel("exec");
            BufferedReader in = new BufferedReader(new InputStreamReader(channel.getInputStream()));
            channel.setCommand(command);
            channel.connect();

            if (channel.getExitStatus() == 0 || channel.isClosed() || channel.isEOF()) {
                logger.info("SSH connection is successful!");                    
            }
            in.close();
        } catch (JSchException jsche) {
            logger.error("Trying to SSH to host: {} but got exception {}", address, jsche);                
        } finally {
            if (channel != null) channel.disconnect();
            if (session != null) session.disconnect();
        }

答案 1 :(得分:0)

我遇到了同样的问题,这是一个类加载问题。另一个库(winzipaes)依赖于另一个版本auf Bouncycastle(bcprov-jdk16),它似乎与SSHJ引用的jdk15版本有冲突。

明确排除jdk16版本对我有帮助(但我还没有测试过使用winzipaes的代码)。

答案 2 :(得分:0)

我在部署Cloudera集群时遇到了同样的问题。确保支持的MAC的客户端和服务器集具有非空的交集。

例如我得到了:

.push

修复方法是将至少一个客户端MAC添加到服务器支持的MAC。在Ubuntu 14.04.2 LTS上使用net.schmizz.sshj.transport.TransportImpl: Dying because - net.schmizz.sshj.transport.TransportException: Unable to reach a settlement: [hmac-sha1, hmac-sha1-96, hmac-md5, hmac-md5-96] and [hmac-sha2-512-etm@openssh.com, hmac-sha2-256-etm@openssh.com, umac-128-etm@openssh.com, hmac-sha2-512, hmac-sha2-256, hmac-ripemd160] 只需在SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2中修改MACs

不确定这里的安全含义,也就是说某些方法可能会被劝阻为弱,但是你明白了,客户端和服务器需要解决这个问题。另请注意,客户端做出选择,服务器将适应。

不要忘记重新启动服务器(如上所述的Ubuntu):/etc/ssh/sshd_config