解决Ubuntu20.04版本ssh升级连接报错server responded”algorithm negotiation failed”

好不容易升到最新版本获取全新体验,结果泪目了~

报错原因:ssh工具版本太低,OpenSSL版本升的比较高,有些算法不支持。

解决办法:修改ssh的配置文件 /etc/ssh/sshd_config。

                   vi /etc/ssh/sshd_config 在配置文件末尾加:

Ciphers 3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes    256-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@opens    sh.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-sha    256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org

                如图:

                   重启ssh服务:service ssh restart

                   如果没有报错,那么you are the luky one!

                  然而,可能报如下错误。一脸懵逼,这是啥玩意?

root@wja-vm:/etc/ssh# service ssh restart
Job for ssh.service failed because the control process exited with error code.
See "systemctl status ssh.service" and "journalctl -xe" for details.
root@wja-vm:/etc/ssh# journalctl -xe
-- 结果为“failed”。
3月 17 22:20:45 wja-vm systemd[1]: ssh.service: Scheduled restart job, restart counter is at 5.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Automatic restarting of the unit ssh.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
3月 17 22:20:45 wja-vm systemd[1]: Stopped OpenBSD Secure Shell server.
-- Subject: ssh.service 单元已结束停止操作
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- ssh.service 单元已结束停止操作。
3月 17 22:20:45 wja-vm systemd[1]: ssh.service: Start request repeated too quickly.
3月 17 22:20:45 wja-vm systemd[1]: ssh.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- The unit ssh.service has entered the 'failed' state with result 'exit-code'.
3月 17 22:20:45 wja-vm systemd[1]: Failed to start OpenBSD Secure Shell server.
-- Subject: ssh.service 单元已失败
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- ssh.service 单元已失败。
-- 
-- 结果为“failed”。

                 调用journalctl -xe命令打印日志,可以看到画圈处十分眼熟,没错这就是问题根源。 查阅(https://kingzcheung.com/archives/116.html)后发现sshd启动的时候会读取配置文件sshd_config内容,然后和一个cipher.c文件比较,如果 ciphers 的数组配置与 sshd_config 不一样的话,就会引发 Bad SSH2 cipher spec 的错误,而升级系统刚好升级了openssh,但是配置并没有改变,所以导致配置与版本不一致。

通过使用ssh -Q cipher命令查看系统版本的ciphers数组内容,置换到前面的sshd_config文件。

oot@wja-vm:/etc/ssh# 
root@wja-vm:/etc/ssh# ssh -Q cipher
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

同样,使用ssh -Q macs,ssh -Q kexalgorithms进行相关内容置换即可。

置换后保存,重启ssh,完美解决。

所查阅的相关资料链接:CSDN博主「ance779」的原创文章,原文链接:https://blog.csdn.net/ance779/article/details/95031345

                                 博客园博主原文链接:https://www.cnblogs.com/xuanbjut/p/13379717.html

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值