问题描述:

  我在使用sshsecureshell登录ubuntu 20.04时出现错误server responded "algorithm negotiation failed”,然后按照百度到的教程修改了/etc/ssh/sshd_config的配置文件,在文件的最后添加了一段表示加密算法的内容,
在百度上看到的要增加的内容如下(是错的,要进行修改),我会把正确的内容放在最后

Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbc

MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-sha1-96,hmac-md5-96

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

之后重启ssh服务时出现错误,提示
Job for ssh.service failed because the control process exited with error code. See “systemctl status ssh.service” and “journalctl -xe” for details.

Job for ssh.service failed because the control process exited with error code.
See "systemctl status ssh.service" and "journalctl -xe" for details.

解决过程:

首先根据提示输入systemctl status ssh.service命令
systemctl status ssh.services
结果如下

在这里插入图片描述输入sshd -T命令查看具体错误原因

sshd -T
/etc/ssh/sshd_config line 128: Bad SSH2 mac spec 'hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-sha1-96,hmac-md5-96'.

这里的内容表示是最后面添加的MACs的内容有错误,可能是ssh版本不一致或者是什么导致的,我们要修改的就是这段内容
输入ssh -Q mac命令查看ssh支持的Macs有那些,把这些内容替换到最后增加的mac中即可
在这里插入图片描述修改之后再次重启ssh如果不出错误就没问题了

如果sshd -T提示的错误是 Bad SSH2 mac spec,就使用ssh -Q mac查看然后修改Macs的内容
如果错误是Bad SSH2 cipher spe,就使用ssh -Q cipher,然后修改配置文件中的cipher的内容

最后附上正确的内容

Ciphers 3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com

MACs hmac-sha1,hmac-sha1-96,hmac-sha2-256,hmac-sha2-512,hmac-md5,hmac-md5-96,umac-64@openssh.com,umac-128@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-md5-etm@openssh.com,hmac-md5-96-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com

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
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐