我该如何修复"kex_exchange_identification: read: Connection reset by peer"的错误?

81
我希望你能在GitLab管道中使用PRIVATE_KEY来使用scp复制数据。
错误信息如下:
kex_exchange_identification: read: Connection reset by peer
Connection reset by x.x.x.x port 22
lost connection

管道日志:
$ mkdir -p ~/.ssh

$ echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa

$ chmod 600 ~/.ssh/id_rsa

$ eval "$(ssh-agent -s)"
Agent pid 22

$ ssh-add ~/.ssh/id_rsa
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

$ ssh-keyscan -H $IP >> ~/.ssh/known_hosts
# x.x.x.x:22 SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.10
# x.x.x.x:22 SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.10

$ scp -rv api.yml root@$IP:/home/services/test/

Executing: program /usr/bin/ssh host x.x.x.x, user root, command scp -v -r -t /home/services/test/

OpenSSH_8.6p1, OpenSSL 1.1.1l  24 Aug 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to x.x.x.x [x.x.x.x] 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_ecdsa_sk type -1
debug1: identity file /root/.ssh/id_ecdsa_sk-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_ed25519_sk type -1
debug1: identity file /root/.ssh/id_ed25519_sk-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.6
kex_exchange_identification: read: Connection reset by peer
Connection reset by x.x.x.x port 22
lost connection

3
当通过ssh连接华芸NAS时,遇到了这个问题。检查 /usr/builtin/etc/ipblock/ipblock.deny 看看是否有任何IP被阻止。我认为这与 /etc/hosts.deny 有些类似。 - dibery
这是一个较新的问题吗(例如,与某些软件的特定版本有关?OpenSSH)?— 来自 Super User(2019)、Unix & Linux(2019)、Super User(2020)、Nixcraft(2021)和 Ask Ubuntu(2022)的一些错误消息。 - Peter Mortensen
那么,是否有一个更早的规范问题?答案没有提供任何版本信息。 - Peter Mortensen
这与GitLab有关吗?所有答案都不具体说明,没有明确指出它是否实际上在GitLab上。 - Peter Mortensen
一次服务器重启解决了我的问题。 - jbrahy
17个回答

0

我遇到了同样的错误。我有一个Ubuntu 20.04主机和两个运行在VMware上的RHEL 8虚拟机。我从Ubuntu终端登录到这两个虚拟机。我同时使用以太网和Wi-Fi连接。每次重启虚拟机后尝试登录时,都会出现以下错误:

kex_exchange_identification: read: Connection reset by peer
Connection reset by x.x.x.x port 22

重新启动sshd服务并不能解决问题。有时,如果我物理断开并重新连接以太网电缆,则问题可能会得到解决。

最后,我使用以下方法关闭了Wi-Fi连接:

nmcli conn down <name_of_Wi-Fi_connection>

或者从设置中关闭它,这为我提供了一个永久性的解决方案。

我的以太网和 Wi-Fi 连接(静态连接)具有相同的 IP 地址,所以我认为虚拟机拒绝了两个“可疑”的类似连接。


请查看 为什么在提问时不上传代码/错误的图片?(例如,"只有在其他方式无法清晰表达问题时才应使用图片,例如提供用户界面的截图。"),并且做正确的事情(它涵盖了答案、程序输入和程序输出**)。提前致谢。 - Peter Mortensen
什么名字?SSID吗?还是其他的东西? - Peter Mortensen

0
今天我在尝试使用运行Ubuntu 20.04.5 LTS(Focal Fossa)的戴尔笔记本电脑并尝试SSH到Raspberry Pi时遇到了这个错误。当我在我的家庭 Wi-Fi网络上尝试SSH到pi(也在我的家庭Wi-Fi网络上)时,我收到了以下错误:
ssh pi@10.0.0.200

输出:

kex_exchange_identification: read: Connection reset by peer'

然而,当我将我的Ubuntu笔记本切换到移动热点时,错误消失了,我能够无问题地进行SSH。一旦我找出解决根本原因的方法,我会尽快更新这篇文章。


问题已解决(但完整原因不明)。我按照此处更改DNS服务器的说明更改为8.8.8.8和8.8.4.4。
大约5分钟后,我能够正常使用命令行终端中的SSH。

树莓派运行的是什么?我在Ubuntu 20.04和我的Pi 3B上遇到了这个问题。我的Raspbian Pi 3B设备从未出现过这个问题。我让它冷却一会儿,稍后再试,它就正常工作了。 - rtaft

0

也许您应该更改主机的分辨率

按win+R,输入C:\ Windows \ System32 \ drivers \ etc打开主机文件的位置: {{link1:enter image description here}}

添加[IP]:域名例如1.1.1.1 google


0
在我的情况下,是由于Synology服务器的私有IP不小心被加入了DSM的阻止列表中。 将其移除并将整个子网添加到允许列表中解决了这个问题。

-2

我也遇到了同样的问题:

我通过以下步骤解决了这个问题。

  1. 编辑文件etc/hosts.allow。命令为sudo nano /etc/hosts.allow
  2. 在末尾,将ALL键的值更新为ALL : ALL,如ALL : ALL。保存文件并重试。

基本上,ALL可能被设置为其他内容,因此在建立与主机的ssh连接时,它期望请求应该来自以10.开头的IP地址,如果ALL设置为ALL : 10.。因此,通过用ALL替换10.,您可以允许从任何地方进行连接。


-2

你可以尝试使用VPN,或者如果之前已经使用过,可以尝试关闭并重新连接。

如果你没有预算购买VPN,可以尝试使用免费的ProtonVPN。当我遇到同样的问题时,它对我很有效。


-2

尝试检查服务器端是否正在运行OpenSSH服务器。

尝试检查sshd配置。这对我有用。


3
目前你的回答不够清晰,请编辑并添加更多细节,以帮助其他人理解它如何回答问题。你可以在帮助中心找到有关如何撰写好答案的更多信息。 - Amit
1
这是一个非常简单化的回答,而且并不太有帮助。 - Frotz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接