SSH连接失败的相关排错

先用ping命令排查是否能够Ping通

使用ssh -v命令

用ssh -v去连有问题的服务器,会有比较详细的调试信息在屏幕上输出,可以帮助判断是哪一步出了问题。

主要是看是客户端还是服务器的问题。如果是客户端的问题,应该log中有写。如果是没有什么有用信息,就可能是服务器端出问题了。

[root@jpeng ~]# ssh -v root@123.207.4.225
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to 10.1.101.35 [10.1.101.35] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
ssh_exchange_identification: read: Connection reset by peer

现在看起来是服务器出问题了,虽然不能ssh到服务器,但可以通过售后工具里VNC进去。

排错思路1:

检查 /etc/hosts.deny 里面是否有 SSHD: 开头的行,有此行表示SSH的客户端IP进入了黑名单,将其注释;
再检查/etc/hosts.allow 里面是否也有 SSHD:开头的行,如果是/etc/hosts.deny没有 SSHD相关内容而/etc/hosts.allow里有SSHD相关内容,这就成了白名单,只有在这个文件里面的IP才能通过SSH连接,也可以先注释

排错思路2:

检查/etc/ssh 目录下相关文件的权限
有碰到过很多例是这种情况,客户的SSHD服务相关key文件权限被修改,导致SSHD服务启动异常。
先执行 ls -l /etc/ssh/*key 查看一下相关文件权限是否有问题

这里我是自己改成了777
执行systemctl restart sshd查看能否正常,即使服务重启没有失败,ssh客户端现在也是无法连接的
再执行systemctl ststus sshd -l查看一下服务状态

输出内容中也明显提到了不能载入文件,提示权限错误。
一般来讲,这些相关文件不需要执行权限,而且也只有root用户可以访问,因此正常重新赋予这些文件 600 或者 640 权限即可。
然后再重启一下服务

chmod 640 /etc/ssh/*key 
systemctl restart sshd 
systemctl status sshd -l

如何导出Windows系统日志

上一篇

Linux平台安装图形界面

下一篇
369