间歇性“ssh_exchange_identification:连接被远程主机关闭”错误

间歇性“ssh_exchange_identification:连接被远程主机关闭”错误

虽然这个网站上有很多问题以及其他解决这个问题的问题,但我还没有找到一个似乎可以解决我所遇到的问题的问题。

当尝试从运行 Lion 的 MBpro ssh linux 机器时,出现以下错误:

gjohnson5@Gentrys-MacBook-Pro:~$ ssh -v user@server_name
OpenSSH_5.6p1, OpenSSL 0.9.8y 5 Feb 2013
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug1: Connecting to server_name[ip_address] port 22.
debug1: Connection established.
debug1: identity file /Users/gjohnson5/.ssh/id_rsa type -1
debug1: identity file /Users/gjohnson5/.ssh/id_rsa-cert type -1
debug1: identity file /Users/gjohnson5/.ssh/id_dsa type -1
debug1: identity file /Users/gjohnson5/.ssh/id_dsa-cert type -1
ssh_exchange_identification: Connection closed by remote host

奇怪的是我间歇性地收到此错误。有时重新启动我的机器并重试将使我进入服务器没有问题。其他时候,错误仍然存​​在。有时,我会成功登录,关闭连接,几秒钟后尝试重新连接,然后收到错误。

现在,我尝试清除该~/.ssh/known_hosts文件,并且发现尝试在同一台计算机上以不同用户身份登录仍然会引发错误。我无法检查/etc/hosts.allow/etc/hosts.deny因为我无法访问服务器,而且不幸的是,我雇主的 IT 没有响应。然而,我无法想象这会成为问题,因为我偶尔能够使用我的机器登录服务器。看来问题可能出在我的机器上的某些配置上(??),尽管我对此相对缺乏经验,并且不知道从哪里开始寻找。

编辑:根据请求,这是检查 MaxStartups 的结果:

grep MaxStartups /etc/ssh/sshd_config
#MaxStartups 10:30:60

答案1

如果传入请求数量较多,则可能会出现此问题。

一旦未经身份验证的连接数量超过 sshd:MaxStartUps 参数,sshd 就会开始拒绝这些连接。

所以最好增加 sshd_config 中的 MaxStartups

哈!

答案2

请检查 /etc/hosts.allow 和 /etc/hosts.deny 文件中定义的规则。那里可能定义了一些规则来允许/阻止来自系统的连接。

重新启动系统后,您的 IP 地址可能会发生变化,有时服务器上拒绝的 IP 会被分配给系统。

答案3

日志说了什么?Connection established.后面的ssh_exchange_identification: Connection closed by remote host表示客户端与服务器端的连接已经建立,但是ssh无法启动。

根据我的拙见,这通常是由于是否

TCP_wrapper阻止 SSH:检查服务器主机上文件 /etc/hosts.{allow,deny} 中的规则是否允许连接到 SSH 守护程序,

或者由于服务器中的拼写错误SSH 守护进程配置这会阻止它按预期回答。日志会告诉你,例如sshd[6652]: fatal: /etc/ssh/sshd_config line 134: Directive 'Port' is not allowed within a Match block

答案4

尝试

lsof -n | grep ssh | grep DEL

相关内容