简体   繁体   English

SSH “kex_exchange_identification:读取:对等连接重置”

[英]SSH "kex_exchange_identification: read: Connection reset by peer"

The setup:设置:

  • Raspberry 3B running Raspbian Stretch 9 on an external HDD and using ZRAM Raspberry 3B 在外部 HDD 上运行 Raspbian Stretch 9 并使用 ZRAM
  • Raspi used as a webserver running LAMP and MERN stacks and accessed remotely via SSH with 1 IDE (Coda for Mac OS) Raspi 用作运行 LAMP 和 MERN 堆栈的网络服务器,并通过 SSH 和 1 个 IDE(Mac OS 的 Coda)远程访问
  • SSH port forwarded by router with static IP SSH 端口由路由器转发 static IP
  • fail2ban running失败2禁令运行

The problem:问题:

When accessing the raspberry from a remote location (over the Internet) via SSH, it works until the connection hangs.当通过 SSH 从远程位置(通过 Internet)访问树莓派时,它会一直工作,直到连接挂起。 This occurs randomly.这是随机发生的。 I can sometimes SSH it again after few minutes, and sometimes not until I restart the Raspi.有时我可以在几分钟后再次 SSH 它,有时直到我重新启动 Raspi。

What I've tried:我试过的:

  • SSH in verbose mode from remote location: SSH 从远程位置处于详细模式:
debug1: Local version string SSH-2.0-OpenSSH_8.1
kex_exchange_identification: read: Connection reset by peer
  • SSH in verbose mode from local network (I actually SSH another machine on the local network remotely, then SSH the Raspi from that machine). SSH 从本地网络处于详细模式(我实际上是 SSH 远程本地网络上的另一台机器,然后 SSH 来自该机器的 Raspi)。 Same result : Connection reset by peer结果相同Connection reset by peer
  • Checked /etc/hosts.allow and /etc/hosts.deny => Nothing there检查/etc/hosts.allow/etc/hosts.deny => 没有
  • Checked iptables via iptables -L --line-number => Nothing there通过iptables -L --line-number =>检查 iptables
  • Checked logs: /var/log/fail2ban.log and sudo journalctl -t sshd => Nothing striking there检查日志: /var/log/fail2ban.logsudo journalctl -t sshd => 没有什么引人注目的
  • Updated sshd_config with no DNS更新了no DNSsshd_config
  • Re-installed SSH via apt-get --reinstall install openssh-server openssh-client通过apt-get --reinstall install openssh-server openssh-client重新安装 SSH

I am running out of ideas here and no clue about what's happening.我在这里没有想法,也不知道发生了什么。 As someone encountered the same problem with SSH connection before?之前有人遇到过与 SSH 连接相同的问题吗? Could it be a load issue on the raspberry?这可能是覆盆子的负载问题吗?

Long story short, my problem had nothing to do with a network issue and was fixed by examining the syslog .长话短说,我的问题与网络问题无关,通过检查syslog已解决。

In details:详细说明:

I noticed that none of the webapps (via LAMP or MERN stacks) while up and running before the issue started, were not reachable anymore.我注意到在问题开始之前启动并运行的所有 Web 应用程序(通过 LAMP 或 MERN 堆栈)都无法再访问。

So I dug up the syslog with the tail -f -n X /var/log/syslog command (replacing X with the number of lines you want to display).因此,我使用tail -f -n X /var/log/syslog命令(将 X 替换为您要显示的行数)挖掘了系统日志。 I then noticed few lines mentioning a Voltage problem (sorry I did keep the exact terms).然后我注意到几行提到电压问题(对不起,我确实保留了确切的条款)。 But basically it meant that my Raspi which an external HDD was plugged on did not have a strong enough power supply.但基本上这意味着我的外接硬盘插入的Raspi没有足够强大的电源。

Then it looked that the HDD was unmounted and the system crashed, which explains all the issues mentioned above.然后看起来硬盘被卸载并且系统崩溃了,这解释了上面提到的所有问题。

So I removed the HDD put the SD card back and ran the Raspi again while going through the syslog again and monitoring the memory with htop .因此,我卸下了 HDD,将 SD 卡放回原处并再次运行 Raspi,同时再次浏览syslog并使用htop监视 memory。 It turned out that when I started both the apache and node servers, the RAM and SWAP memories were getting full repeating the same consequences mentioned above.事实证明,当我同时启动 apache 和节点服务器时,RAM 和 SWAP 内存已满,重复上述相同的结果。

So finally I increased the SWAP memory by using ZRAM.所以最后我通过使用 ZRAM 增加了 SWAP memory。 Link here . 链接在这里

Now everything runs well but still monitoring.现在一切运行良好,但仍在监控。

I didn't see ufw (firewall) was installed.我没有看到安装了ufw(防火墙)。

ufw disable

(Or configure ufw.)

Now the ports are reachable as expected.现在端口可以按预期访问。

I found another scenario that causes this precise error.我发现了导致这个精确错误的另一种情况。 Be sure you check permissions on the OpenSSH generated public / private key files in /etc/ssh on the host system you are trying to connect to with SSH.请务必检查您尝试使用 SSH 连接的主机系统上 /etc/ssh 中 OpenSSH 生成的公钥/私钥文件的权限。 These keys are used by the SSH daemon.这些密钥由 SSH 守护程序使用。

Since OpenSSH is cross platform the same would apply to any operating system running SSHd.由于 OpenSSH 是跨平台的,因此同样适用于任何运行 SSHd 的操作系统。 These files must have the proper permissions.这些文件必须具有适当的权限。

/etc/ssh is the default path but if you are on Windows or other OS it may vary. /etc/ssh 是默认路径,但如果您使用的是 Windows 或其他操作系统,它可能会有所不同。 But for most Unix/Linux/macOS systems it should be /etc/ssh.但对于大多数 Unix/Linux/macOS 系统,它应该是 /etc/ssh。

sudo chmod 600 *_key
sudo chmod 644 *.pub

You should also verify that the SSH client has the correct permissions on the ~/.ssh and the public / private keys, config, authorized_keys, etc. Although if these are wrong you will be told right away.您还应该验证 SSH 客户端对 ~/.ssh 和公钥/私钥、配置、授权密钥等是否具有正确的权限。尽管如果这些是错误的,您会立即被告知。 But when the permissions on keys for the SSH daemon are wrong you receive errors in the logs.但是,当 SSH 守护程序的密钥权限错误时,您会在日志中收到错误消息。

When it's not DNS nor certificates, then it's always permissions.当它不是 DNS 也不是证书时,它总是权限。

Another scenario where the error: kex_exchange_identification: read: Connection reset by peer appears is a configuration restricting access via ssh in hosts.allow with a line like: sshd: 192.168.178.12 and then trying to ssh from an IP different then then one above. Another scenario where the error: kex_exchange_identification: read: Connection reset by peer appears is a configuration restricting access via ssh in hosts.allow with a line like: sshd: 192.168.178.12 and then trying to ssh from an IP different then then one above.

I need medical attention for my foot now....我的脚现在需要就医......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ssh git kex_exchange_identification:读取:对等方重置连接 - ssh git kex_exchange_identification: read: Connection reset by peer 怎么修? “kex_exchange_identification:读取:连接由对等方重置” - How to fix? "kex_exchange_identification: read: Connection reset by peer" GitHub 错误 - “ssh_exchange_identification: read: Connection reset by peer” - GitHub error - “ssh_exchange_identification: read: Connection reset by peer” ssh_exchange_identification读取连接由同行重置 - Homestead Laravel - ssh_exchange_identification read connection reset by peer - Homestead Laravel ssh_exchange_identification:读取:对等方重置连接; Docker中的ubuntu - ssh_exchange_identification: read: Connection reset by peer; ubuntu in Docker Vagrant Windows - ssh_exchange_identification:读取:对等方重置连接 - Vagrant Windows - ssh_exchange_identification: read: Connection reset by peer gitlab - ssh_exchange_identification:读取:对等方重置连接 - gitlab - ssh_exchange_identification: read: Connection reset by peer bibucket ssh_exchange_identification:读取:对等方重置连接 - bibucket ssh_exchange_identification: read: Connection reset by peer ssh_exchange_identification:读取:对等方重置连接 - ssh_exchange_identification: read: Connection reset by peer macOS 更新后 SSH“kex_exchange_identification”错误 - SSH "kex_exchange_identification" error after macOS update
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM