如何修复“ssh_exchange_identification: read: Connection reset by peer”错误?

use*_*879 50 ssh

我无法使用我的电脑通过 ssh 连接到我的服务器,但我可以使用 termius 应用程序通过我的手机连接到我的服务器。我检查过/etc/hosts.allow/etc/hosts.deny我的 iptables,我也搜索过谷歌,似乎没有适合这个问题的答案。我不知道如何解决它,这是ssh -v 183.17.228.80输出

debug1: Connecting to 183.17.228.80 [183.17.228.80] port 22.
debug1: Connection established.=======================   
debug1: permanently_set_uid: 0/0   
debug1: SELinux support disabled  
debug1: key_load_public: No such file or directory    
debug1: identity file /root/.ssh/id_rsa type -1    
debug1: key_load_public: No such file or directory   
debug1: identity file /root/.ssh/id_rsa-cert type -1      
debug1: key_load_public: No such file or directory   
debug1: identity file /root/.ssh/id_dsa type -1   
debug1: key_load_public: No such file or directory   
debug1: identity file /root/.ssh/id_dsa-cert type -1   
debug1: key_load_public: No such file or directory   
debug1: identity file /root/.ssh/id_ecdsa type -1  
debug1: key_load_public: No such file or directory   
debug1: identity file /root/.ssh/id_ecdsa-cert type -1   
debug1: key_load_public: No such file or directory  
debug1: identity file /root/.ssh/id_ed25519 type -1   
debug1: key_load_public: No such file or directory  
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_7.2p2 Ubuntu-4ubuntu2.2   
ssh_exchange_identification: read: Connection reset by peer
Run Code Online (Sandbox Code Playgroud)

我可以ping这个服务器,这里是telnet

telnet 183.17.228.29 22  
Trying 183.17.228.29...  
Connected to 183.17.228.29.  
Escape character is '^]'.                                                                 
Connection closed by foreign host.
Run Code Online (Sandbox Code Playgroud)

小智 38

只需重新启动您想要 ssh 的服务器。它对我有用,以前我遇到过同样的问题。

  • 重启服务器是一个非常非常糟糕的建议。 (22认同)
  • 当 ssh 到我在 AWS 上的免费服务器时,我遇到了同样的问题。它是由服务器内存耗尽引起的。重启工作。 (5认同)
  • 找不到根本原因,但重新启动对我有用。 (2认同)
  • 如果重新启动工作,它可能不是配置问题,而是资源问题。也许增加 ssh 的优先级可能已经成功了。 (2认同)

小智 14

这实际上意味着您的 IP 被服务器列入黑名单。尝试将您的 IP 地址列入白名单以便能够登录。您可以查看 /etc/hosts 列表以查看您的服务器的 IP 地址是否已更改。

  • 事实并非如此。 (22认同)
  • 这对我来说似乎是真的。我发现我的 Cloudways 服务器已将我的家庭 IP 列入黑名单,我需要手动将其列入白名单。 (2认同)

小智 7

我解决问题的方法是我去主机并运行了一些命令。

sudo mkdir /var/run/sshd
sudo chmod 755 -R /var/run/sshd
sudo service ssh restart
Run Code Online (Sandbox Code Playgroud)

在那之后,我连接到了机器。


小智 5

看起来服务器上的 ssh 守护进程已挂起。你确定它正在运行吗?当您 telnet 到 ssh 时,您必须看到签名。就像是:

telnet unixhow.com 22
Trying 35.228.26.20...
Connected to unixhow.com.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.1
Run Code Online (Sandbox Code Playgroud)

我从你的输出中看到的是 ssh 守护进程在服务器端没有响应。我建议通过 IP-KVM(或其他方式)连接到远程计算机并重新启动 sshd。


小智 5

我遇到了同样的问题,但在重新启动 sshd 守护进程后,我可以连接到主机。

sudo systemctl restart sshd && systemctl status sshd
Run Code Online (Sandbox Code Playgroud)

这只是一个临时解决方法,直到您增加 MaxAuthTries 参数。


Rom*_*nov 4

当您尝试对服务器进行身份验证失败的次数有限制并且客户端上的 ssh 密钥过多(超过 MaxAuthTries 的值)时,就会发生上述错误

您可以尝试增加 MaxAuthTries 的值并重新启动 sshd 守护进程。或者,您可以限制目录中的密钥数量~/.ssh,并使用子目录和~/.ssh/config文件来定义每个主机/主机组的密钥

  • 你尝试了什么?请更新您的问题 (3认同)

小智 0

  1. 检查服务器上的 sshd 是否已安装并正在运行。
  2. 确保守护程序已安装并启动。您必须能够“man sshd”。我认为它所在的包是 open-ssl,您需要启动守护进程(并在不需要时停止它。)。