SSH连接:ssh_exchange_identifcation


9

我已经通过Mac连接到远程服务器大约一个月了。不过,从最近开始,我尝试使用ssh dylan @ MY_IP进行连接并收到此消息。

ssh_exchange_identification: read: Connection reset by peer

我也得到了一些诊断信息...

debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to {MY IP{ [MY IP] port 22.
debug1: Connection established.
debug1: identity file /Users/watson/.ssh/id_rsa type -1
debug1: identity file /Users/watson/.ssh/id_rsa-cert type -1
debug3: Incorrect RSA1 identifier
debug3: Could not load "/Users/watson/.ssh/id_dsa" as a RSA1 public key
debug1: identity file /Users/watson/.ssh/id_dsa type 2
debug1: identity file /Users/watson/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2

经过研究,我尝试了以下方法...

  1. 重新启动我的路由器
  2. 清除了我的“ known_hosts”文件
  3. 删除了我的“ known_hosts”文件
  4. 发布并续订了我的DHCP
  5. 我也尝试过使用Putty在另一个设备(Windows)上也出现错误

请注意,我没有对服务器进行任何更改以禁止这种通信。

另外,我不确定这是否会引起问题,但是我已经通过它的域名和IP连接到它了。

此外,我还能够从另一个IP地址成功连接。

我知道这是一个大问题,有很多资源可供使用,但是许多解决方案都行不通,我也没有为任何人看到任何类型的解决方案。

更新资料

我将其强制为协议1。现在,我收到的不是“由对等方重置连接”,而是“由远程主机关闭了连接”。显示调试信息并运行它:

debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to MY_IP [MY_IP] port 22.
debug1: Connection established.
debug1: identity file /Users/watson/.ssh/identity type -1
debug1: identity file /Users/watson/.ssh/identity-cert type -1
ssh_exchange_identification: Connection closed by remote host

您是否使用公钥身份验证?你有钥匙/Users/watson/.ssh/id_dsa吗?尝试备份文件并将其删除。
pabouk

我不使用公钥身份验证;但是,文件中只有一个密钥。我尝试删除该文件,但是运行命令没有任何更改。
Dylan

如果协议版本有问题,您可以通过ssh -1 ...
wkaha 2013年

请参阅帖子的新编辑。
Dylan

Answers:


4

这是解决连接SSH服务器时出现的“ ssh_exchange_identification:连接被远程主机关闭”错误的方法。

在将软件包解压到根目录后,尝试连接到嵌入式Linux计算机时出现此错误。许多库文件被替换,包括libssl。

尝试连接:

chetic@ubuntu:~$ ssh -v root@192.168.1.100
OpenSSH_6.2p2 Ubuntu-6ubuntu0.3, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to SC [192.168.1.100] port 22.
debug1: Connection established.
debug1: identity file /home/delaval/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/delaval/.ssh/id_rsa-cert type -1
debug1: identity file /home/delaval/.ssh/id_dsa type -1
debug1: identity file /home/delaval/.ssh/id_dsa-cert type -1
debug1: identity file /home/delaval/.ssh/id_ecdsa type -1
debug1: identity file /home/delaval/.ssh/id_ecdsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2p2 Ubuntu-6ubuntu0.3
ssh_exchange_identification: read: Connection reset by peer

谷歌搜索似乎只建议检查hosts.deny和hosts.allow,但我的目标计算机没有此类文件。

重新启动后(按照Karthik的建议),sshd没有运行。我尝试在目标上手动启动sshd:

# sshd
OpenSSL version mismatch. Built against 1000002f, you have 1000105f

我用原始版本替换了/usr/lib/libssl.a并启动了sshd,一切恢复正常。在我的情况下,问题是由最初解压到根目录的软件包中的版本错误引起的。


3

我遇到了同样的错误(但是来自任何计算机,包括麻烦的计算机ssh localhost)。

它是在我迁移用户个人资料时开始的;即在将文件复制为root之后,然后执行如下命令chown -R username /Users/username/Destop

无论如何,完全不确定为什么将/ var / empty所有者更改为用户名,但是ssh绝对需要/var/empty由root拥有(否则您将获得ssh_exchange_identification: read: Connection reset by peer):

    sudo chown root /var/empty

谢谢!更改所有者已/var/empty为我解决了此问题。
Yevhen Pavliuk

1

这不是本地计算机的问题,而是服务器端的问题。可能有多个因素导致此问题:

  1. 远程服务器上/etc/hosts.allow或/etc/hosts.deny配置中的更改。
  2. 繁重的服务器负载。

过去,遇到这些问题时,我按以下顺序完成了两件事之一:

  1. 修改以上文章中引用的/etc/hosts.allow。(并重新启动SSH服务器)
  2. 如果/etc/hosts.allow已经是必需的方式,则只需重新启动SSH服务器(在执行此操作时要小心!)
  3. 如果重启不起作用,请重新生成服务器密钥,然后重新启动SSH服务器(这是有风险的,因为每个登录此计算机的用户都会收到有关更改了密钥的服务器的错误)

通常,1可以解决问题,但在某些情况下我必须做2。我无法弄清楚为什么会这样,仅能解决问题。可能与密钥的显示方式有关,或者它以某种方式被破坏了-我不确定。但是我所知道的是,错误完全与服务器有关,以及在设置SSH连接时握手的方式。


1

我使用Cygwin设置了SSH,就我而言,正是Windows防火墙导致了此错误,因此请确保允许连接到端口22。


0

我自己很轻松地解决了这个问题。

在普通的OS X中,您可以通过在“系统偏好设置/共享”中切换“远程登录”来解决此问题。

但是,如果它是无头服务器(例如我的情况),则可以使用OSX Server应用程序转到(您的服务器名称)/设置,然后切换“再次打开和关闭安全外壳连接”


1
我还指出了如何解决该问题,但并不能解决问题:禁用远程登录会严重影响系统,并且每次有人要SSH到某个特定位置时都必须切换远程登录不是一个可行的解决方案。 。
Ant6n

是的,这仍然是我面临的可怕问题。我刚刚制作了一个根cron脚本,该脚本在每个午夜重新启动服务。
塞伦斯

0

如果使用私钥或安全密钥登录服务器,则需要使用以下命令将密钥文件的权限更改为660:

sudo chmod 660文件名


1
(1)虽然这可能是ssh无法正常工作的原因,但尚不清楚此问题将如何随机影响正常工作的系统。(2)这样的答案(例如它)对识别正在讨论的文件或提供允许用户识别它的说明会更有用。(3)我猜您是在谈论用户主目录(下)中的文件。如果是这样,就sudo没有必要了。
斯科特,
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.