kex_exchange_identification: Connection closed by remote host
通过内网主机或者远程主机ssh登陆概率性失败,最高登陆失败率达到80%左右。
内网win主机登陆表现为登陆失败,需要反复登陆多次,因为这台主机是我内网的集中管控服务器,不能轻易的重装或者调整,整个大内网都靠它去监控和维护。期间尝试过更改各种配置,包括某乎帖子中的各种操作。 无效!!!
尝试从别的服务器ssh登陆,报错信息如下:
[root@localhost ]# ssh -vvv tset@192 .168 .XX .XX
OpenSSH_8.1p1, OpenSSL 1.0.2p 14 Aug 2018
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname 192.168.XX.XX is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.XX.XX [192.168.XX.XX] port 22.
debug1: Connection established.
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: identity file /root/.ssh/id_xmss type -1
debug1: identity file /root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
kex_exchange_identification: Connection closed by remote host
或是 expecting SSH2_MSG_KEX_ECDH_REPLY
百度报错信息无果,全是这个报错信息ssh_exchange_identification: Connection closed by remote host,根本没有我要找的KEX,无奈,只能尝试更改并行登陆参数和最大连接数。
MaxSessions:最大允许链接数,默认10.
MaxStartups:最大允许保持多少个未认证链接(未输入登录密码),默认值是10.
#MaxStartups 10:30:100 原配置指定SSH守护进程未经身份验证的并发连接的最大数量,默认值是 10:30:100。10:30:100表示的意思是,从第10个连接开始,以30%的概率(递增)拒绝新的连接,指导连接数达到100。
sshd的MaxStartups配置限制了可以并行认证的客户端数量为10,别问我为啥知道,自己登陆上去看cat /etc/ssh/sshd_config |grep MaxStartups 就知道了。
可查看ssh连接数
netstat -nat | grep -i '22' | wc -l 或者lsof -i:22 |wc -l
我将
MaxSessions 改成 2000
MaxStartups 也改成2000
然后重启sshd服务
世界终于太平无事了。
原来都是并发连接惹的祸。
评论