SSH 客户端关闭连接

SSH 客户端关闭连接

我正在尝试在运行 OS X 10.9.5 的 MacBook (192.168.1.3) 和运行 Korora 23 (基本上是 Fedora 23,安装时附加了应用程序、软件包和存储库) 的台式计算机 (192.168.1.2) 之间建立双向 SSH 通信。我已将每台计算机设置为主机和客户端。可以成功地从 OS X 客户端 ssh 到 Linux 主机,但从 Linux 客户端到 OS X 主机会导致此输出 (我已将端口号替换为 xxxxx):

$ ssh MacBook -vvv
OpenSSH_7.2p2, OpenSSL 1.0.2g-fips  1 Mar 2016
debug1: Reading configuration data /home/alex/.ssh/config
debug1: /home/alex/.ssh/config line 1: Applying options for *
debug1: /home/alex/.ssh/config line 4: Applying options for MacBook
debug3: kex names ok: [diffie-hellman-group-exchange-sha256]
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "192.168.1.3" port xxxxx
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.168.1.3 [192.168.1.3] port xxxxx.
debug1: Connection established.
debug1: identity file /home/alex/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/alex/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2
debug1: Remote protocol version 2.0, remote software version    OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 192.168.1.3:xxxxx as 'alex'
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: diffie-hellman-group-exchange-sha256,ext-info-c
debug2: host key algorithms: ssh-rsa
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-  ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128- cbc,aes192-cbc,aes256-cbc,arcfour
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256- ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour
debug2: MACs ctos: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160
debug2: MACs stoc: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160
debug2: compression ctos: [email protected],zlib,none
debug2: compression stoc: [email protected],zlib,none
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-rsa
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: compression ctos: none,[email protected]
debug2: compression stoc: none,[email protected]
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug1: kex: algorithm: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-md5 compression: [email protected]
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-md5 compression: [email protected]
debug1: kex: diffie-hellman-group-exchange-sha256 need=16 dh_need=16
debug1: kex: diffie-hellman-group-exchange-sha256 need=16 dh_need=16
debug3: send packet: type 34
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<3072<8192) sent
debug3: receive packet: type 31
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 1543/3072
debug3: send packet: type 32
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug3: receive packet: type 33
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:gv0L2YQKQKyddwo09OecUJcy/W5ACn/PxzmhBqh9i4I
debug3: put_host_port: [192.168.1.3]:xxxxx
debug3: put_host_port: [192.168.1.3]:xxxxx
debug3: hostkeys_foreach: reading file "/home/alex/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/alex/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from [192.168.1.3]:xxxxx
debug3: hostkeys_foreach: reading file "/home/alex/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/alex/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from [192.168.1.3]:xxxxx
debug1: Host '[192.168.1.3]:xxxxx' is known and matches the RSA host key.
debug1: Found key in /home/alex/.ssh/known_hosts:1
debug2: bits set: 1520/3072
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug2: set_newkeys: mode 0
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS received
debug2: key: /home/alex/.ssh/id_rsa (0x5605a87e8660), explicit
debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey
debug3: authmethod_lookup publickey
debug3: remaining preferred: 
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/alex/.ssh/id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).

在 OS X 主机上/private/var/log/system.log唯一相关的条目似乎是:

MacBook.local sshd[2291]: 192.168.1.2 [preauth] 关闭连接

Linux 上的所有权和权限:

$ ls -al /home
total 32
drwxr-xr-x.  4 alex alex  4096 Apr  7 15:49 .
dr-xr-xr-x. 18 root root  4096 Feb  6 13:59 ..
drwx------. 28 alex alex  4096 Apr 12 15:07 alex
drwx------.  2 root root 16384 Apr  7 15:41 lost+found
$ ls -al ~/.ssh/
total 32
drwx------.  2 alex alex 4096 Apr 11 16:40 .
drwx------. 28 alex alex 4096 Apr 12 15:07 ..
-rw-------.  1 alex alex  400 Apr  4 23:50 authorized_keys
-rw-------.  1 alex alex 2540 Apr 12 13:48 config
-rw-------.  1 alex alex 1679 Apr 11 16:28 id_rsa
-rw-r--r--.  1 alex alex  394 Apr 11 16:28 id_rsa.pub
-rw-------.  1 alex alex  401 Apr 11 16:40 known_hosts

在 OS X 上:

ls -al ~/.ssh/
total 64
drwx------   8 alex  alex    272 11 Apr 16:43 .
drwxr-xr-x@ 73 alex  staff  2482 12 Apr 15:13 ..
-rw-r--r--@  1 alex  alex   6148 11 Apr 16:43 .DS_Store
-rw-------@  1 alex  alex    719 11 Apr 16:39 authorized_keys.rtf
-rw-------@  1 alex  alex   2556  5 Apr 00:13 config
-rw-------   1 alex  alex   1675  4 Apr 23:04 id_rsa
-rw-r--r--   1 alex  alex    400  4 Apr 23:04 id_rsa.pub
-rw-------   1 alex  alex    401  8 Apr 22:31 known_hosts

authorized_keys还在两台计算机上尝试了 644 权限known_hosts。已从 Linux 客户端(问题似乎出在这里)重新发布了密钥对,但没有任何变化。我手动将客户端的公钥粘贴到主机的authorized_keys文件中,确保密钥在一行中;还将它们粘贴到路由器的 SSH 身份验证密钥字段中。

我已经在 Google 上搜索并阅读了几个小时;找不到太多内容可以解决以下内容,而这些内容似乎是问题的关键:

debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method

客户端关闭连接的情况似乎比主机关闭连接的情况少见得多。

将非常感激您的帮助。


感谢 axiac 发现了我的愚蠢错误。除了看到 .rtf 扩展名并意识到格式错误之外,其他输出是否提供了解决问题的线索?

我进入该文件的“获取信息”,删除了 .rtf,用 iText Express 打开,进入“样式”并勾选“纯文本”,保存在 /.ssh 中,更改所有权和权限,删除另一个authorized_keys文件,重新启动 Mac,最后可以从 Linux 客户端连接!在对文件、防火墙、权限进行所有配置之后——在 2 个不同的操作系统、SELinux、路由器上,也许还有其他我记不清的配置,一切都归结为 1 个文件的愚蠢字体错误。SSH 是一种在 2 台计算机之间传输文件的绝佳协议,但绝对不宽容,而且不容易正确使用。尤其是在使用不同的操作系统并希望双向传输时。再次感谢。

答案1

问题出在您的 OSX 机器上。您authorized_keys使用默认的 OSX“文本”编辑器编辑了该文件,它自动将.rtf(富文本格式)扩展名附加到该文件。

重命名~/.ssh/authorized_keys.rtf,然后~/.ssh/authorized_keys使用纯文本编辑器(等)打开它vinano检查它不包含 RTF 标记代码。

它应该与 Linux 机器上的文件相同id_rsa.pub。(它可以在单独的行中包含多个公钥。)

相关内容