代码中使用sshd进行服务器连接,遇见报错:
Key exchange was not finished, connection is closed.
是ssh中的key交换算法不兼容导致,解决方案是在/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
关于KexAlgorithms的配置项详情参考官网:https://www.ssh.com/academy/ssh/sshd_config
核心是diffie-hellman-group1-sha1 是开启兼容算法,但是这个算法比较老,容易被中间人攻击。
修改后重启服务:
service sshd restart