代碼中使用sshd進(jìn)行服務(wù)器連接,遇見報錯:
Key exchange was not finished, connection is closed.
是ssh中的key交換算法不兼容導(dǎo)致,解決方案是在/etc/ssh/sshd_config最后添加如下行內(nèi)容解決問題:
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
關(guān)于KexAlgorithms的配置項詳情參考官網(wǎng):https://www.ssh.com/academy/ssh/sshd_config
核心是diffie-hellman-group1-sha1 是開啟兼容算法,但是這個算法比較老,容易被中間人攻擊。
修改后重啟服務(wù):
service sshd restart