java.io.IOException: There was a problem while connecting to ip:端口2
at ch.ethz.ssh2.Connection.connect(Connection.java:699)
at ch.ethz.ssh2.Connection.connect(Connection.java:490)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Key exchange was not finished, connection is closed.
at ch.ethz.ssh2.transport.KexManager.getOrWaitForConnectionInfo(KexManager.java:91)
at ch.ethz.ssh2.transport.TransportManager.getConnectionInfo(TransportManager.java:229)
at ch.ethz.ssh2.Connection.connect(Connection.java:655)
... 13 more
Caused by: java.io.IOException: Cannot negotiate, proposals do not match.
at ch.ethz.ssh2.transport.KexManager.handleMessage(KexManager.java:412)
at ch.ethz.ssh2.transport.TransportManager.receiveLoop(TransportManager.java:753)
at ch.ethz.ssh2.transport.TransportManager$1.run(TransportManager.java:468)
... 1 more



通过上述源码可以看出:ganymed默认采用的为Diffie-Hellman 算法,由于 Diffie-Hellman 算法的安全性存在漏洞,高版本的 OpenSSH 已经移除了该算法。OpenSSH 7.0 及更高版本中,Diffie-Hellman 算法已被默认禁用,但仍然可以通过在配置文件中进行设置启用它,所以:连接高版本openssh则需要调整服务器sshd_config,考虑到后续高版本openssh可能移除该算法,顾调整配置方案算应急处理方式,推荐通过代码兼容该方式。
修改配置方式:
1、修改配置文件/etc/ssh/sshd_config 添加如下配置:
KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org
2、重启sshd
systemctl restart sshd