与主机的连接被远程主机关闭。退出状态-1

与主机的连接被远程主机关闭。退出状态-1

我运行一个虚拟的 ubuntu 服务器,通常连接起来没有问题。然而在过去的 4 天里我得到了两次connection closed by remote host。我有多个帐户,但每个帐户都得到相同的结果。重新启动后我能够再次登录。

这是我无法登录时得到的结果

 ssh -vvv user@host_name
OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /home/user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "host_name" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to host_name [IP.IP.IP.IP] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to host_name:22 as 'user'
debug3: hostkeys_foreach: reading file "/home/user/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /home/user/.ssh/known_hosts:23
debug3: load_hostkeys: loaded 1 keys from host_name
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],ecdsa-sha2-nistp521-c
[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: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,dif
fie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected]
m,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],ssh-ed25519,rsa-sha2-512,r
sa-sha2-256,ssh-rsa
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes128-cbc,aes192-c
bc,aes256-cbc,3des-cbc
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes128-cbc,aes192-c
bc,aes256-cbc,3des-cbc
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],hmac-sha1-etm@openssh.
com,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],hmac-sha1-etm@openssh.
com,[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: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,dif
fie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected]
om,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],[email protected]
om,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],h
[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,umac-64@openss
h.com,[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],h
[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,umac-64@openss
h.com,[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 
debug1: kex: algorithm: [email protected]
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:eJMfyQRvAyYtV7qR3eZHoHJv4um5NlkZ6lqOM5+3/x8
debug3: hostkeys_foreach: reading file "/home/user/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /home/user/.ssh/known_hosts:23
debug3: load_hostkeys: loaded 1 keys from host
debug3: hostkeys_foreach: reading file "/home/user/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /home/user/.ssh/known_hosts:24
debug3: load_hostkeys: loaded 1 keys from IP.IP.IP.IP
debug1: Host 'host' is known and matches the ECDSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:23
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
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug2: key: user@local (0x5587cbcb1630), agent
debug2: key: user@local (0x5587cbcaf4f0), agent
debug2: key: user@local (0x5587cbcaf560), agent
debug2: key: user@local (0x5587cbcb1260), agent
debug2: key: user@local (0x5587cbcb12b0), agent
debug2: key: /home/user/.ssh/id_rsa ((nil))
debug2: key: /home/user/.ssh/id_dsa ((nil))
debug2: key: /home/user/.ssh/id_ecdsa ((nil))
debug2: key: /home/user/.ssh/id_ed25519 ((nil))
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: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: user@local
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,password
debug1: Offering RSA public key: user@local
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,password
debug1: Offering RSA public key: user@local
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug2: input_userauth_pk_ok: fp SHA256:sc7ESM4WTnxwcB1WLlNt0P34/j0U2c/SbDL2d9re7VA
debug3: sign_and_send_pubkey: RSA SHA256:sc7ESM4WTnxwcB1WLlNt0P34/j0U2c/SbDL2d9re7VA
debug3: send packet: type 50
debug3: receive packet: type 53
debug3: input_userauth_banner
System is booting up.
debug1: Authentication succeeded (publickey).
Authenticated to host ([IP.IP.IP.IP]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting [email protected]
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: send packet: type 1
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t3 r-1 i0/0 o0/0 fd 5/6 cc -1)

Connection to host closed by remote host.
Connection to host closed.
Transferred: sent 4028, received 2672 bytes, in 0.0 seconds
Bytes per second: sent 45293985.3, received 30046059.8
debug1: Exit status -1

解决我的问题

  • 我跟着发布并打开

    $(which sshd) -Ddp 10222
    

    我能够登录

    ssh -p 10222 user@host
    
  • 我没有使用hosts.allowhosts.deny

  • 我有一个帐户没有关联的 ssh 密钥。但即使输入正确的密码,我也会收到相同的错误消息。

  • /etc/ssh/sshd_config

     #MaxStartups #is not used
    

我还可以采取哪些其他步骤来确保 ssh 配置正确。

答案1

“此消息意味着客户端与服务器建立了 TCP 连接,但服务器在 SSH 协议启动之前立即关闭了该连接(ssh_exchange_identification 例程实现版本字符串交换,这是协议的初始步骤)。这通常是因为检查服务器日志libwrap,如果这是问题,您将看到如下消息:

SSH1, OpenSSH sshd1[15092]: refused connect from 192.168.10.1
SSH2 sshd2[15085]: Denied connection from by 192.168.10.1 tcp wrappers.

如果编译支持 SSH 服务器,请检查服务器主机上的libwrap (TCP-wrappers)文件中的规则是否允许连接到 SSH 守护程序。/etc/hosts.{allow,deny}例如,这样的条目将允许从任何源地址连接到 sshd:

sshd sshd1 sshd2 : ALL : ALLOW

左侧的名称必须是argv[0]正在运行的守护进程的值,因此如果您使用其他名称调用 sshd,则需要使用该名称。此外,规则与顺序相关,因此刚刚给出的规则可能不起作用,具体取决于其他规则及其相对位置。hosts_access(5)有关libwrap规则语法和语义的详细信息,请参阅手册页。”

看: SSH 常见问题解答

另外,请参阅此条目:服务器故障,非常有帮助的答案。

相关内容