远程连接CentOS服务器时发现有这样的报错: Connection closed by remote host
ssh 加上 -v 参数打印下debug信息:
root@CentOS6.5 ~ # ssh -v 172.17.0.10
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 172.17.0.10 [172.17.0.10] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/identity-cert type -1
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
ssh_exchange_identification: Connection closed by remote host
看ssh debug提示很明确,服务器主动断开连接无法远程连接,这里就需要通过VNC登陆服务器检查服务器端了,可以从以下几个方面排查解决:
- CVM安全组、防火墙 iptables、firewalld 等是否有对源地址的限制
- 检查 /etc/hosts.deny 和 /etc/hosts.allow 文件是否配置拒绝了本地IP连接到服务器
- ssh会话数量太多,修改sshd_config中的MaxSessions参数,增加会话数量(服务器连接一直没有问题,突然出现此报错)
- 以上排查都没有问题重启sshd服务看下,或者检查服务器CPU、外网带宽等资源是否负载过高