为什么会发生这种情况:连接被[我的主机IP]端口22关闭

为什么会发生这种情况:连接被[我的主机IP]端口22关闭

这是在运行 Buster 的 Pi 4 上进行的。

我正在尝试从此 Pi ssh 到 Web 主机 (HostGator)。

我知道 ssh 正在主机上运行,​​因为我可以使用 rsa 密钥对从 Mac ssh 到 HostGator,无需密码:

MrMuscle:~ mnewman$ ssh mgnewman@[my host]
Last login: Sat Aug 22 17:47:47 2020 from 1.20.171.54
mgnewman@[my host] [~]#

我知道 SSH 可以在 Pi 上运行,因为我可以在没有密码的情况下 ssh 进入 Mac:

pi@raspsky:~/.ssh $ ssh [email protected]
Last login: Sun Aug 23 06:11:14 2020 from 192.168.0.65.
MrMuscle:~ mnewman$

主机位于known_hosts 文件中:

pi@raspsky:~/.ssh $ ssh-keygen -F [my host]
# Host mgnewman.com found: line 1

该 Pi 的 SD 卡是从另一个 Pi 4 克隆的。在新 Pi 上,我生成了新的公钥/私钥以及新的authorized_keys 和known_hosts 文件。

有人知道我如何让它发挥作用吗?

长话短说:

pi@raspsky:~/.ssh $ ssh mgnewman@[my host]
Connection closed by [my host IP] port 22

当公钥发送到主机时,Pi 的调试输出如下所示:

debug1: Offering public key: id_rsa RSA SHA256:4fUCtJQoMfxO/Za1goxtEjx5fyFq0tHgkus4jIhI7dE explicit
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
Connection closed by [myhost IP] port 22

以下是 Mac 上的调试输出中的相同行:

debug1: Offering public key: /Users/mnewman/.ssh/id_rsa RSA SHA256:2RluaUDGj/vNTMBi9DD1nEHT/Ets+qwbdvo+E7DsKS0
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: /Users/mnewman/.ssh/id_rsa RSA SHA256:2RluaUDGj/vNTMBi9DD1nEHT/Ets+qwbdvo+E7DsKS0
debug1: Authentication succeeded (publickey).
Authenticated to [myhost] ([my host IP]:22).
debug1: channel 0: new [client-session]

整个详细输出:

pi@raspsky:~/.ssh $ ssh -vvv mgnewman@[my host]
OpenSSH_7.9p1 Raspbian-10+deb10u2, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "[my host]" port 22
debug2: ssh_connect_direct
debug1: Connecting to [my host] [[my host IP]] port 22.
debug1: Connection established.
debug1: identity file /home/pi/.ssh/id_rsa type 0
debug1: identity file /home/pi/.ssh/id_rsa-cert type -1
debug1: identity file /home/pi/.ssh/id_dsa type -1
debug1: identity file /home/pi/.ssh/id_dsa-cert type -1
debug1: identity file /home/pi/.ssh/id_ecdsa type -1
debug1: identity file /home/pi/[my host].ssh/id_ecdsa-cert type -1
debug1: identity file /home/pi/.ssh/id_ed25519 type -1
debug1: identity file /home/pi/.ssh/id_ed25519-cert type -1
debug1: identity file /home/pi/.ssh/id_xmss type -1
debug1: identity file /home/pi/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9p1 Raspbian-10+deb10u2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000002
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to [my host]:22 as 'mgnewman'
debug3: hostkeys_foreach: reading file "/home/pi/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/pi/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from [my host]
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa
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: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-```
debug2: host key algorithms: [email protected],[email protected],[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa,[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected],zlib
debug2: compression stoc: none,[email protected],zlib
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
debug2: host key algorithms: ssh-rsa,ssh-dss
debug2: ciphers ctos: aes256-ctr,aes192-ctr,aes128-ctr
debug2: ciphers stoc: aes256-ctr,aes192-ctr,aes128-ctr
debug2: MACs ctos: hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,[email protected]
debug2: MACs stoc: hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,[email protected]
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-sha2-256 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug3: send packet: type 34
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<8192<8192) sent
debug3: receive packet: type 31
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 4114/8192
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:zvfdYBMDWtOFnGjLosCOjO9MNKNaLHVcYNJSg6Wx428
debug3: hostkeys_foreach: reading file "/home/pi/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/pi/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from [my host]
debug3: hostkeys_foreach: reading file "/home/pi/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/pi/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys from [my host IP]
debug1: Host '[my host]' is known and matches the RSA host key.
debug1: Found key in /home/pi/.ssh/known_hosts:1
debug2: bits set: 4034/8192
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
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 4294967296 blocks
debug1: Will attempt key: /home/pi/.ssh/id_rsa RSA SHA256:4fUCtJQoMfxO/Za1goxtEjx5fyFq0tHgkus4jIhI7dE
debug1: Will attempt key: /home/pi/.ssh/id_dsa
debug1: Will attempt key: /home/pi/.ssh/id_ecdsa
debug1: Will attempt key: /home/pi/.ssh/id_ed25519
debug1: Will attempt key: /home/pi/.ssh/id_xmss
debug2: pubkey_prepare: done
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,password,keyboard-interactive
debug3: start over, passed a different list publickey,password,keyboard-interactive
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/pi/.ssh/id_rsa RSA SHA256:4fUCtJQoMfxO/Za1goxtEjx5fyFq0tHgkus4jIhI7dE
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
Connection closed by [my host IP] port 22

答案1

我真的不确定这里发生了什么。我永远无法让 rsa 工作,所以我想我应该尝试 ecdsa。我生成了一个密钥对,并将公共 ecdsa 密钥复制到主机上的authorized_keys 文件中。我尝试使用 ssh 进行连接,并且成功了:

pi@raspsky:~/.ssh $ ssh -i /home/pi/.ssh/id_ecdsa mgnewman@[myhost].com
Last login: Sun Aug 23 23:53:26 2020 from 1.20.171.54
mgnewman@[myhost].com [~]# exit

然后我又尝试了rsa。它也起作用了。

当我粘贴 ecdsa 密钥时,我是否以某种方式“修复”了authorized_keys 文件?或许。

相关内容