云服务器 ECS Linux SSH 无法远程登录问题,SSH 登录时出现如下错误:No supported key exchange algorithms
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
处理办法
要解决此问题,针对前述不同情况,请依次进行如下配置检查或修改:
检查文件权限
检查文件有效性
检查文件权限
SSH 服务会对相关密钥文件的权限进行检查。比如,私钥文件默认权限是 600,如果配置成 777 等其它权限,导致其它用户也有读取或修改权限。则 SSH 服务会认为该配置存在安全风险,进而导致客户端连接失败。
可以通过如下指令恢复相关文件的默认权限配置:
cd /etc/ssh/
chmod 600 ssh_host_*
chmod 644 *.pub
操作示意如下:
[root@centos]# cd /etc/ssh/
[root@centos]# chmod 600 ssh_host_*
[root@centos]# chmod 644 *.pub
[root@centos]# ll
total 156
-rw-------. 1 root root 125811 Nov 23 2013 moduli
-rw-r--r--. 1 root root 2047 Nov 23 2013 ssh_config
-rw------- 1 root root 3639 May 16 11:43 sshd_config
-rw------- 1 root root 668 May 20 23:31 ssh_host_dsa_key
-rw-r--r-- 1 root root 590 May 20 23:31 ssh_host_dsa_key.pub
-rw------- 1 root root 963 May 20 23:31 ssh_host_key
-rw-r--r-- 1 root root 627 May 20 23:31 ssh_host_key.pub
-rw------- 1 root root 1675 May 20 23:31 ssh_host_rsa_key
-rw-r--r-- 1 root root 382 May 20 23:31 ssh_host_rsa_key.pub
检查文件有效性
如果参阅前述步骤,修改相关文件权限后,还是无法正常连接。由于 SSH 服务在启动时会自动重建丢失的密钥文件。所以,也可以直接将相关文件删除并重启 SSH 服务,让相关文件自动生成。
相关指令如下:
cd /etc/ssh/
rm -rf ssh_host_*
service sshd restart
操作示意如下:
[root@centos]# cd /etc/ssh/
[root@centos]# ll
total 156
-rw-------. 1 root root 125811 Nov 23 2013 moduli
-rw-r--r--. 1 root root 2047 Nov 23 2013 ssh_config
-rw------- 1 root root 3639 May 16 11:43 sshd_config
-rw------- 1 root root 672 May 20 23:08 ssh_host_dsa_key
-rw-r--r-- 1 root root 590 May 20 23:08 ssh_host_dsa_key.pub
-rw------- 1 root root 963 May 20 23:08 ssh_host_key
-rw-r--r-- 1 root root 627 May 20 23:08 ssh_host_key.pub
-rw------- 1 root root 1675 May 20 23:08 ssh_host_rsa_key
-rw-r--r-- 1 root root 382 May 20 23:08 ssh_host_rsa_key.pub
[root@centos]# rm -rf ssh_host_*
[root@centos]# ll
total 132
-rw-------. 1 root root 125811 Nov 23 2013 moduli
-rw-r--r--. 1 root root 2047 Nov 23 2013 ssh_config
-rw------- 1 root root 3639 May 16 11:43 sshd_config
[root@centos]# service sshd restart
Stopping sshd: [ OK ]
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd: [ OK ]
[root@centos]# ll
total 156
-rw-------. 1 root root 125811 Nov 23 2013 moduli
-rw-r--r--. 1 root root 2047 Nov 23 2013 ssh_config
-rw------- 1 root root 3639 May 16 11:43 sshd_config
-rw------- 1 root root 668 May 20 23:16 ssh_host_dsa_key
-rw-r--r-- 1 root root 590 May 20 23:16 ssh_host_dsa_key.pub
-rw------- 1 root root 963 May 20 23:16 ssh_host_key
-rw-r--r-- 1 root root 627 May 20 23:16 ssh_host_key.pub
-rw------- 1 root root 1671 May 20 23:16 ssh_host_rsa_key
-rw-r--r-- 1 root root 382 May 20 23:16 ssh_host_rsa_key.pub
补充说明:对于 Ubuntu 、Debain 类操作系统,修复指令如下:
sudo rm -r /etc/ssh/ssh*key
sudo dpkg-reconfigure openssh-server
如果还有问题,可以参阅云服务器 ECS Linux SSH 无法登录问题排查指引做进一步排查分析。