突然出现 ssh_exchange_identification:远程主机关闭连接

突然出现 ssh_exchange_identification:远程主机关闭连接

我在远程机器上运行着 Ubuntu 10.10。我每天都可以 ssh 连接它,没有任何问题,但今天突然出现了以下错误:

ssh_exchange_identification: Connection closed by remote host

如果我连接-vv,我会得到以下信息:

OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/bla/.ssh/config
debug1: Applying options for ubuntu-server
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to ubuntu-server.com [123.123.123.123] port 22.
debug1: Connection established.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug2: key_type_from_name: unknown key type '-----END'
debug1: identity file /Users/bla/.ssh/id_rsa type -1
debug1: identity file /Users/bla/.ssh/id_rsa-cert type -1
ssh_exchange_identification: Connection closed by remote host

如果我删除密钥,我会得到完全相同的输出(无“debug2:key_type_...”)。我设法物理登录并检查了我的,hosts.allowhosts.deny它们没有条目。我尝试删除并重新安装 OpenSSH,检查authorized_keys~/.ssh权限并尝试从其他计算机连接,但只得到相同的错误。我已经束手无策了,任何帮助都将不胜感激。

答案1

对于我来说,在 CentOS7 上,这是由于大量暴力登录尝试加上MaxStartupssshd 的默认设置造成的。

手册页sshd_配置有话要说:

最大创业公司

指定与 SSH 守护程序的最大并发未经身份验证的连接数。额外的连接将被丢弃,直到身份验证成功或连接的 LoginGraceTime 到期。默认值为 10。

或者,可以通过指定三个冒号分隔的值“start:rate:full”(例如“10:30:60”)来启用随机早期丢弃。如果当前有“start”(10)个未经身份验证的连接,sshd(8) 将以“rate/100”(30%)的概率拒绝连接尝试。如果未经身份验证的连接数量达到“full”(60),则概率会线性增加,并且所有连接尝试都将被拒绝。

将起始值设置为 25(例如MaxStartups 25:30:100)即可/etc/ssh/sshd_config解决问题。

答案2

几乎可以肯定该/etc/hosts.deny文件有你的机器的条目,添加

sshd: xxx.yyy.zzz.aaa

将你的连接 IP 地址添加到 /etc/hosts.allow

答案3

同样的错误

ssh_exchange_identification:远程主机关闭连接

当私钥(文件)可被所有人读取时,即具有错误的权限时,就会发生这种情况。

例如,如果任何私钥

  • ssh_host_key
  • ssh_host_dsa_key
  • ssh_host_rsa_key

/etc/ssh/chmod 644(应该是chmod 600)。

以下权限导致“ssh_exchange_identification:远程主机关闭连接”错误:

root@host:/etc/config/ssh# ls -la
drwxrwxrwx    2 root     root            0 Aug 24  2005 .
drw-rw-rw-    3 root     root            0 Apr  3  2007 ..
-rw-r--r--    1 root     root        88039 Aug 24  2005 moduli
-rw-r--r--    1 root     root         1559 Aug 24  2005 ssh_config
-rw-r--r--    1 root     root          668 Aug 24  2005 ssh_host_dsa_key
-rw-r--r--    1 root     root          599 Aug 24  2005 ssh_host_dsa_key.pub
-rw-r--r--    1 root     root          524 Aug 24  2005 ssh_host_key
-rw-r--r--    1 root     root          328 Aug 24  2005 ssh_host_key.pub
-rw-r--r--    1 root     root          883 Aug 24  2005 ssh_host_rsa_key
-rw-r--r--    1 root     root          219 Aug 24  2005 ssh_host_rsa_key.pub
-rw-r--r--    1 root     root         2018 Aug 25  2005 sshd_config

更正权限后,现在应该可以接受连接:

root@host:/etc/config/ssh# ls -la                    
drwxrwxrwx    2 root     root            0 Aug 24  2005 .
drw-rw-rw-    3 root     root            0 Apr  3  2007 ..
-rw-r--r--    1 root     root        88039 Aug 24  2005 moduli
-rw-r--r--    1 root     root         1559 Aug 24  2005 ssh_config
-rw-------    1 root     root          668 Aug 24  2005 ssh_host_dsa_key
-rw-r--r--    1 root     root          599 Aug 24  2005 ssh_host_dsa_key.pub
-rw-------    1 root     root          524 Aug 24  2005 ssh_host_key
-rw-r--r--    1 root     root          328 Aug 24  2005 ssh_host_key.pub
-rw-------    1 root     root          883 Aug 24  2005 ssh_host_rsa_key
-rw-r--r--    1 root     root          219 Aug 24  2005 ssh_host_rsa_key.pub
-rw-r--r--    1 root     root         2018 Aug 25  2005 sshd_config

答案4

执行某项操作时可能会出现新的防火墙。我曾经遇到过一个问题,在引入新防火墙时也出现了同样的问题。新防火墙是在服务器端引入的。

相关内容