使用SSH命令登录Linux实例时出现“No supported key exchange algorithms”错误
使用SSH连接Linux系统的ECS实例时,客户端或服务端的secure日志中可能会出现类似如下信息,用户无法正常登录。 - Read from socket failed: Connection reset by peer.
- Connection closed by 192.X.X.1.
- sshd error: could not load host key.
- fatal: No supported key exchange algorithms [preauth].
- DSA host key for 192.X.X.1 has changed and you have requested strict checking.
- Host key verification failed.
- ssh_exchange_identification: read: Connection reset by peer.
问题原因该问题通常是由于SSH服务相关的密钥文件异常所致,如下所示。 - 相关密钥文件异常,比如文件损坏、被删除或篡改等。
- 相关密钥文件权限配置异常,导致无法正确读取。
解决方案要解决此问题,针对问题原因中不同情况,请依次进行如下配置检查或修改。 检查文件权限SSH服务会对相关密钥文件的权限进行检查。比如,私钥文件默认权限是600,如果配置成777等其它权限,导致其它用户也有读取或修改权限。则SSH服务会认为该配置存在安全风险,进而导致客户端连接失败。 - 登录实例,参考如下命令,恢复相关文件的默认权限。
- cd /etc/ssh/
- chmod 600 ssh_host_*
- chmod 644 *.pub
复制代码
- 执行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_host_*文件。系统显示类似如下。
- 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
复制代码
- 执行如下命令,删除相关文件。提示:对于Ubuntu、Debain类的操作系统,删除相关文件的命令如下所示。
sudo rm -r /etc/ssh/ssh*key - 执行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
复制代码
- 执行如下命令,重启SSH服务,自动生成相关文件。提示:对于Ubuntu、Debain类的操作系统,重启SSH服务的命令如下所示。
sudo dpkg-reconfigure openssh-server - 执行ll命令,确认成功生成ssh_host_*文件。
- 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
复制代码
如果还存在问题,可以参阅通过SSH无法远程登录Linux实例的排查指引,进一步排查分析
|