Java后端通过ssh连接mac电脑报错问题

211 阅读1分钟

问题

连接失败,后台和mac机无法进行ssh的连接

报错信息

java.io.IOException: Key exchange was not finished, connection is closed.
...
Caused by: java.io.IOException: Cannot negotiate, proposals do not match.
...

原因

后端加密太老旧

ganymed-ssh2代码ch.ethz.ssh2.transport.KexManager中只支持了三种算法

public static final String[] getDefaultClientKexAlgorithmList() {  
       return new String[]{"diffie-hellman-group-exchange-sha1", "diffie-hellman-group14-sha1", "diffie-hellman-group1-sha1"};  
}

解决方式

要连接服务器的/etc/ssh/sshd_config添加配置

HostKeyAlgorithms +ssh-rsa
 
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

重启sshd

关闭:sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
启动:sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist 查看:sudo launchctl list | grep sshd

最后

这么好的文章再不关注,以后就见不到了