原文网址:https://www.youyong.top/article/1158e1d6d167
使用 SSH 连接云服务器 ECS (Elastic Compute Server) Linux 服务器时,客户端或服务端 secure 日志(可以通过 管理终端 进入系统查看)中可能会出现类似如下信息,导致无法正常连接服务器:
原文网址:https://www.youyong.top/article/1158e1d6d167
使用 SSH 连接云服务器 ECS (Elastic Compute Server) Linux 服务器时,客户端或服务端 secure 日志(可以通过 管理终端 进入系统查看)中可能会出现类似如下信息,导致无法正常连接服务器:
原文网址:https://www.youyong.top/article/1158e1d6d167
该问题通常是由于 SSH 服务相关的密钥文件异常所致,可能的原因包括:
要解决此问题,针对前述不同情况,请依次进行如下配置检查或修改:
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 无法登录问题排查指引做进一步排查分析。
共 0 条留言
阿里云·业务运营团队内部的前端构建和工程化工具 Dawn开源
SSH 服务启动时出现如下错误:main process exited, code=exited
SSH 登录时出现如下错误:Permission denied, please try again
启动SSH服务时出错:Bad configuration options,怎么解决?
iPhone X 跌破发行价,苏宁200亿入股恒大 | 财经日日评
资深黄牛现身说法:iPhone X价格秒变不停,就像炒股一样
手机扫一扫
分享文章