ganymed组件ssh连接openssh高版本报错

文章讲述了在Java使用SSH2库连接到OpenSSH服务器时遇到的IOException,由于OpenSSH版本较高,默认禁用了不安全的Diffie-Hellman算法。为了解决这个问题,建议在服务器的sshd_config中添加支持旧算法的配置项,并重启sshd服务,作为临时解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值