连接关闭于端口 22 树莓派 4

连接关闭于端口 22 树莓派 4

简而言之:我在通过 ssh 连接到 Raspberry Pi 4 时遇到问题。有一段时间工作正常,但现在我突然收到 Connection closed by <IP> port 22错误消息。

现在,长度有点长,我的设置有点特殊,所以这里是解释。

我在一艘货船上安装了传感器(用于研究目的),并使用 Rpi4 构建了一个数据记录器。我的所有传感器均由 Teensy 3.6 处理,它通过串行将数据发送到 Rpi。 Rpi 从串行端口读取数据并将其存储在与其连接的 SSD 上。 Pi 连接到 4G 调制解调器(能够连接到世界各地大多数现有网络)。

在工作中,我们有一个 Pi 连接到的 OpenVPN 服务器。这样,每当船在港口时,Pi 都会设置为连接到 VPN,我对我的计算机执行相同的操作,并且我可以 ssh 到 pi 来获取之前收集的数据。准确地说,我还在 pi 上安装了一个 UPS,经过编程可以在断电时正确关闭。这样我就可以要求船上的船员通过切断电源来重新启动整个系统。 Pi 运行的是 2019 年 10 月推出的 Raspbian buster 版本。

该系统去年(2019 年 11 月至 12 月)已经安装了几个月,运行良好,但有一个例外:每当船舶改变国家(离开一个港口,即暂时失去 4G 连接,然后到达另一个港口) ),Pi 不再连接到 VPN 服务器。每次我都要求工作人员重新启动整个系统,然后就没事了。

现在我再次安装了系统,为了尝试每次都让 pi 正确连接到 VPN 服务器,我尝试给它一个固定的 IP 地址,而不是使用 DHCP。现在船已经到达一个新端口,我可以从 VPN 服务器看到 Pi 已连接,我可以 ping 它并得到正确的答案,但我无法 ssh 到它,我只得到错误消息Connection closed by <IP> port 22。我知道当我在船上安装系统时 ssh 正在工作:这是我用来检查它是否正常工作的方法。我什至在船离开港口的第二天就下载了数据,当时它距离海岸足够近,仍然有网络。

我现在已经要求工作人员重新启动系统,看看这是否有帮助,但我不确定这是否有帮助,我想找到一个解决方案,而不是一直询问。有人有主意吗?我认为没有必要提及它,但我无法访问 Pi,因为这艘船现在在另一个国家,并且很快将穿越大西洋......

预先感谢您的任何帮助 ! :-)

这是我现在得到的ssh -vvv pi@<IP>

OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug3: Failed to open file:C:/Users/Ulysse/.ssh/config error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolve_canonicalize: hostname 10.8.0.46 is address
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 10.8.0.46 [10.8.0.46] port 22.
debug1: Connection established.
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_rsa error:2
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_rsa.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Ulysse/.ssh/id_rsa type -1
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_rsa-cert error:2
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_rsa-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Ulysse/.ssh/id_rsa-cert type -1
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_dsa error:2
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_dsa.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Ulysse/.ssh/id_dsa type -1
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_dsa-cert error:2
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_dsa-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Ulysse/.ssh/id_dsa-cert type -1
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_ecdsa error:2
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_ecdsa.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Ulysse/.ssh/id_ecdsa type -1
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_ecdsa-cert error:2
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_ecdsa-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Ulysse/.ssh/id_ecdsa-cert type -1
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_ed25519 error:2
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_ed25519.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Ulysse/.ssh/id_ed25519 type -1
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_ed25519-cert error:2
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_ed25519-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Ulysse/.ssh/id_ed25519-cert type -1
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_xmss error:2
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_xmss.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Ulysse/.ssh/id_xmss type -1
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_xmss-cert error:2
debug3: Failed to open file:C:/Users/Ulysse/.ssh/id_xmss-cert.pub error:2
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\Ulysse/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9p1 Raspbian-10+deb10u1
debug1: match: OpenSSH_7.9p1 Raspbian-10+deb10u1 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 10.8.0.46:22 as 'pi'
debug3: hostkeys_foreach: reading file "C:\\Users\\Ulysse/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file C:\\Users\\Ulysse/.ssh/known_hosts:4
debug3: load_hostkeys: loaded 1 keys from 10.8.0.46
debug3: Failed to open file:C:/Users/Ulysse/.ssh/known_hosts2 error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
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-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
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
debug2: compression stoc: none
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server 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
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,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]
debug2: compression stoc: none,[email protected]
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:bPCJlDvO1VwV9Jjtd07xeGMYhvpLRCowVMvtglsTRL4
debug3: hostkeys_foreach: reading file "C:\\Users\\Ulysse/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file C:\\Users\\Ulysse/.ssh/known_hosts:4
debug3: load_hostkeys: loaded 1 keys from 10.8.0.46
debug3: Failed to open file:C:/Users/Ulysse/.ssh/known_hosts2 error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
debug1: Host '10.8.0.46' is known and matches the ECDSA host key.
debug1: Found key in C:\\Users\\Ulysse/.ssh/known_hosts:4
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 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 134217728 blocks
debug3: unable to connect to pipe \\\\.\\pipe\\openssh-ssh-agent, error: 2
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug2: key: C:\\Users\\Ulysse/.ssh/id_rsa (0000000000000000)
debug2: key: C:\\Users\\Ulysse/.ssh/id_dsa (0000000000000000)
debug2: key: C:\\Users\\Ulysse/.ssh/id_ecdsa (0000000000000000)
debug2: key: C:\\Users\\Ulysse/.ssh/id_ed25519 (0000000000000000)
debug2: key: C:\\Users\\Ulysse/.ssh/id_xmss (0000000000000000)
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
Connection closed by 10.8.0.46 port 22

答案1

可能发生的情况是 ssh 不喜欢间歇性连接/断开连接或 IP 地址更改。可能有效的是Mosh,据称它可以处理间歇性连接和漫游功能。

相关内容