如何从Linux客户端ssh到OS X主机没有错误消息“ssh_exchange_identification:连接被远程主机关闭”?


1

我的局域网包括运行Linux的台式计算机(Debian Wheezy),带有OS X Mavericks的MacBook和调制解调器路由器; Linux主机和OS X客户端的ssh运行良好 - 从客户端连接到主机没有问题。

此外,我试图实现反向 - Linux计算机也成为客户端,OS X计算机也成为主机。但尝试从Linux客户端ssh到OS X主机导致

ssh_exchange_identification: Connection closed by remote host

无论Mac防火墙是打开还是关闭,都会发生这种情况。

我尝试了谷歌搜索建议的众多解决方案,包括:

在此处 输入链接描述

(系统不允许我发布更多链接。)

我很确定文件所有权,权限,配置都是正确的。

相同的端口,例如1234,在每台计算机上配置为ssh,作为主机和客户端; 来自两台计算机的netstat命令指示侦听端口1234。DenyHosts和fail2ban都没有安装。

在Linux客户端上,/ var / log / auth.log不提供任何相关消息。

从客户端到主机的Telneting给出

Connection closed by foreign host.

在OS X主机上,在尝试ssh连接时:

/var/log/appfirewall.log显示

MacBook.local socketfilterfw[636] <Info>: sshd-keygen-wrapper: Allow TCP CONNECT (in:1 out:0

/var/log/system.log显示

MacBook.local com.apple.preference.security.remoteservice[662]: nsc_smb XPC: handle_event error : < Connection invalid >

似乎问题在于OS X主机,解决它的关键可能在于这些消息,但我一直无法找到有用的信息。

在MacBook上,系统偏好设置>安全和隐私>防火墙>防火墙选项,“远程登录(SSH)”和“sshd-keygen-wrapper”设置为“允许传入连接”。

在“系统偏好设置”>“共享”中启用“远程登录”。

什么可能导致ssh连接问题以及如何解决它?

自初始发布以来的附加信息

感谢您的回复,但我已经完成了链接中列出的所有内容,使用我的用户名(alex)作为用户进行远程登录,并在每次有关ssh的更改后重新启动两台计算机上的ssh,然后重新启动两台计算机。还在Linux计算机上多次重新安装ssh,并在两台计算机上多次生成新密钥。

也许我应该在两个客户端的ssh_config中澄清一下

PasswordAuthentication no
PubkeyAuthentication yes

这是来自OS X主机的请求输出:(不确定它是多么有用,因为我已经将ssh端口从默认的22更改为1234)

MacBook:~ alex$ ssh -vvv localhost
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [::1] port 22.
debug1: connect to address ::1 port 22: Connection refused
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: connect to address 127.0.0.1 port 22: Connection refused
debug1: Connecting to localhost [fe80::1%lo0] port 22.
debug1: connect to address fe80::1%lo0 port 22: Connection refused
ssh: connect to host localhost port 22: Connection refused

其他澄清信息:

MacBook:~ alex$ ssh -vvv -p 1234 localhost
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [::1] port 1234.
debug1: connect to address ::1 port 1234: Connection refused
debug1: Connecting to localhost [127.0.0.1] port 1234.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/Users/alex/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /Users/alex/.ssh/id_rsa type 1
debug1: identity file /Users/alex/.ssh/id_rsa-cert type -1
debug1: identity file /Users/alex/.ssh/id_dsa type -1
debug1: identity file /Users/alex/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
ssh_exchange_identification: Connection closed by remote host
MacBook:~ alex$ 

请求Linux客户端的输出:

alex@desktop:~$ ssh -v alex@MacBook.local
OpenSSH_6.0p1 Debian-4+deb7u2, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: /etc/ssh/ssh_config line 102: Applying options for *
debug1: Connecting to MacBook.local [192.168.0.3] port 1234.
debug1: Connection established.
debug1: identity file /home/alex/.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/alex/.ssh/id_rsa-cert type -1
ssh_exchange_identification: Connection closed by remote host
alex@desktop:~$ 

经过很多努力让ssh使用Linux作为主机和OS X作为客户端,我认为反过来会相对简单。也许是,但不是到目前为止!将非常感谢进一步的帮助。

拉尔斯

MacBook:~ alex$ sudo sshd -t
Password:
/etc/sshd_config: No such file or directory
MacBook:~ alex$

sshd_config文件位于/ private / etc / ssh中,ssh_config和ssh_host密钥文件也是如此。

问题解决了

我将sshd_config的副本放入/ private / etc并且完成了sudo sshd -t。输出给出了格式错误,表明样式错误并引用了rtf。字体是时代。我从Linux计算机复制了该文件,并在此过程中从纯文本更改了字体。

我将/ private / etc / ssh中的sshd_config文件更改为纯文本,在Mac上的系统首选项>共享中切换“远程登录”,从Linux客户端发出ssh命令,并且能够连接到OS X主机第一次。

我之前没有遇到过这个sshd -t命令,所以感谢Lars引起我的注意并指出我正确的方向。解决方案确实很简单,但确定不是。


sudo sshd -t你的Mac上是否注意到任何配置问题?
Lars Rohrbach 2014年

Answers:


0

您可能需要在Mac上启用远程访问。跟着这些步骤..

  1. 在Mac上,打开“共享首选项”并选择“远程登录”
  2. 指定可以登录的用户:所有用户或“仅这些用户”。

然后你应该能够通过命令ssh到它。

ssh -v user@macOSX-hostname

如果没有连接,请剪切/粘贴整个连接,以便我们可以看到它失败的位置。-v应该给你一些信息。

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.