客户端操作系统:macOS 13.4 服务器操作系统:Ubuntu Linux 20.04 LTS(VPS)11.22.33.44 是实际 VPS IP 的占位符。
当我以 root 身份登录到运行网站的 VPS 时,需要两分钟才能连接。我对其进行了调试,发现它等待了pledge: filesystem
。我检查了一下,桌面没有满,只使用了 200 GB 中的 30 GB。当我以普通用户身份登录时,它会立即连接。
连接到服务器的其他协议(OpenVPN、https)会立即连接,因此不存在延迟问题。而通过 ssh 连接到其他(本地和在线)ssh 服务器最多只需几秒钟。因此这也不是 DNS 问题,但为了排除这种可能性,我使用了 IP 地址而不是域名,但这在两分钟内连接速度也很慢。
为了调试这个命令我调用了:
ssh -vvv [email protected] exit 2>&1 | while read line; do printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$line"; done > "ssh-debug.log"
发现于
https://www.golinuxcloud.com/add-timestamp-to-ssh-verbose-logs/
在那两分钟内,我甚至无法中止连接尝试:Ctrl+C 不起作用。
[2023-07-23 13:11:50] OpenSSH_9.0p1, LibreSSL 3.3.6
[2023-07-23 13:11:50] debug1: Reading configuration data /Users/myuser/.ssh/config
[2023-07-23 13:11:50] debug1: Reading configuration data /etc/ssh/ssh_config
[2023-07-23 13:11:50] debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
[2023-07-23 13:11:50] debug1: /etc/ssh/ssh_config line 54: Applying options for *
[2023-07-23 13:11:50] debug2: resolve_canonicalize: hostname 11.22.33.44 is address
[2023-07-23 13:11:50] debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/myuser/.ssh/known_hosts'
[2023-07-23 13:11:50] debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/myuser/.ssh/known_hosts2'
[2023-07-23 13:11:50] debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
[2023-07-23 13:11:50] debug3: ssh_connect_direct: entering
[2023-07-23 13:11:50] debug1: Connecting to 11.22.33.44 [11.22.33.44] port 22.
[2023-07-23 13:11:50] debug3: set_sock_tos: set socket 3 IP_TOS 0x48
[2023-07-23 13:11:50] debug1: Connection established.
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_rsa type 0
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_rsa-cert type -1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_ecdsa type -1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_ecdsa-cert type -1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_ecdsa_sk type -1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_ecdsa_sk-cert type -1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_ed25519 type 3
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_ed25519-cert type -1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_ed25519_sk type -1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_ed25519_sk-cert type -1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_xmss type -1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_xmss-cert type -1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_dsa type 1
[2023-07-23 13:11:50] debug1: identity file /Users/myuser/.ssh/id_dsa-cert type -1
[2023-07-23 13:11:50] debug1: Local version string SSH-2.0-OpenSSH_9.0
[2023-07-23 13:11:50] debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.7
[2023-07-23 13:11:50] debug1: compat_banner: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.7 pat OpenSSH* compat 0x04000000
[2023-07-23 13:11:50] debug2: fd 3 setting O_NONBLOCK
[2023-07-23 13:11:50] debug1: Authenticating to 11.22.33.44:22 as 'root'
[2023-07-23 13:11:50] debug3: record_hostkey: found key type ECDSA in file /Users/myuser/.ssh/known_hosts:3
[2023-07-23 13:11:50] debug3: load_hostkeys_file: loaded 1 keys from 11.22.33.44
[2023-07-23 13:11:50] debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
[2023-07-23 13:11:50] debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
[2023-07-23 13:11:50] debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],ecdsa-sha2-nistp256
[2023-07-23 13:11:50] debug3: send packet: type 20
[2023-07-23 13:11:50] debug1: SSH2_MSG_KEXINIT sent
[2023-07-23 13:11:50] debug3: receive packet: type 20
[2023-07-23 13:11:50] debug1: SSH2_MSG_KEXINIT received
[2023-07-23 13:11:50] debug2: local client KEXINIT proposal
[2023-07-23 13:11:50] debug2: KEX algorithms: [email protected],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,ext-info-c
[2023-07-23 13:11:50] debug2: host key algorithms: [email protected],ecdsa-sha2-nistp256,[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256
[2023-07-23 13:11:50] debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
[2023-07-23 13:11:50] debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
[2023-07-23 13:11:50] 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
[2023-07-23 13:11:50] 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
[2023-07-23 13:11:50] debug2: compression ctos: none,[email protected],zlib
[2023-07-23 13:11:50] debug2: compression stoc: none,[email protected],zlib
[2023-07-23 13:11:50] debug2: languages ctos:
[2023-07-23 13:11:50] debug2: languages stoc:
[2023-07-23 13:11:50] debug2: first_kex_follows 0
[2023-07-23 13:11:50] debug2: reserved 0
[2023-07-23 13:11:50] debug2: peer server KEXINIT proposal
[2023-07-23 13:11:50] 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
[2023-07-23 13:11:50] debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519
[2023-07-23 13:11:50] debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
[2023-07-23 13:11:50] debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
[2023-07-23 13:11:50] 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
[2023-07-23 13:11:50] 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
[2023-07-23 13:11:50] debug2: compression ctos: none,[email protected]
[2023-07-23 13:11:50] debug2: compression stoc: none,[email protected]
[2023-07-23 13:11:50] debug2: languages ctos:
[2023-07-23 13:11:50] debug2: languages stoc:
[2023-07-23 13:11:50] debug2: first_kex_follows 0
[2023-07-23 13:11:50] debug2: reserved 0
[2023-07-23 13:11:50] debug1: kex: algorithm: curve25519-sha256
[2023-07-23 13:11:50] debug1: kex: host key algorithm: ecdsa-sha2-nistp256
[2023-07-23 13:11:50] debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
[2023-07-23 13:11:50] debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
[2023-07-23 13:11:50] debug3: send packet: type 30
[2023-07-23 13:11:50] debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
[2023-07-23 13:11:50] debug3: receive packet: type 31
[2023-07-23 13:11:50] debug1: SSH2_MSG_KEX_ECDH_REPLY received
[2023-07-23 13:11:50] debug1: Server host key: ecdsa-sha2-nistp256 SHA256:0dSYFvhEjytSvHdUYQdPFsuxuW8P4p1LzCytns1g+p4
[2023-07-23 13:11:50] debug3: record_hostkey: found key type ECDSA in file /Users/myuser/.ssh/known_hosts:3
[2023-07-23 13:11:50] debug3: load_hostkeys_file: loaded 1 keys from 11.22.33.44
[2023-07-23 13:11:50] debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
[2023-07-23 13:11:50] debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
[2023-07-23 13:11:50] debug1: Host '11.22.33.44' is known and matches the ECDSA host key.
[2023-07-23 13:11:50] debug1: Found key in /Users/myuser/.ssh/known_hosts:3
[2023-07-23 13:11:50] debug3: send packet: type 21
[2023-07-23 13:11:50] debug2: ssh_set_newkeys: mode 1
[2023-07-23 13:11:50] debug1: rekey out after 134217728 blocks
[2023-07-23 13:11:50] debug1: SSH2_MSG_NEWKEYS sent
[2023-07-23 13:11:50] debug1: expecting SSH2_MSG_NEWKEYS
[2023-07-23 13:11:50] debug3: receive packet: type 21
[2023-07-23 13:11:50] debug1: SSH2_MSG_NEWKEYS received
[2023-07-23 13:11:50] debug2: ssh_set_newkeys: mode 0
[2023-07-23 13:11:50] debug1: rekey in after 134217728 blocks
[2023-07-23 13:11:50] debug1: get_agent_identities: ssh_get_authentication_socket: No such file or directory
[2023-07-23 13:11:50] debug1: Skipping ssh-dss key /Users/myuser/.ssh/id_dsa - corresponding algo not in PubkeyAcceptedAlgorithms
[2023-07-23 13:11:50] debug1: Will attempt key: /Users/myuser/.ssh/id_rsa RSA SHA256:Mh8uuwZwf0zVhPGPmZ/i7SVHlikZmAleGnj9kphNMts
[2023-07-23 13:11:50] debug1: Will attempt key: /Users/myuser/.ssh/id_ecdsa
[2023-07-23 13:11:50] debug1: Will attempt key: /Users/myuser/.ssh/id_ecdsa_sk
[2023-07-23 13:11:50] debug1: Will attempt key: /Users/myuser/.ssh/id_ed25519 ED25519 SHA256:ZJ+grijrDZCBHEnwsNaU9tiMqLWuqXDEZDGBQfyU2Ss
[2023-07-23 13:11:50] debug1: Will attempt key: /Users/myuser/.ssh/id_ed25519_sk
[2023-07-23 13:11:50] debug1: Will attempt key: /Users/myuser/.ssh/id_xmss
[2023-07-23 13:11:50] debug2: pubkey_prepare: done
[2023-07-23 13:11:50] debug3: send packet: type 5
[2023-07-23 13:11:50] debug3: receive packet: type 7
[2023-07-23 13:11:50] debug1: SSH2_MSG_EXT_INFO received
[2023-07-23 13:11:50] debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected]>
[2023-07-23 13:11:50] debug3: receive packet: type 6
[2023-07-23 13:11:50] debug2: service_accept: ssh-userauth
[2023-07-23 13:11:50] debug1: SSH2_MSG_SERVICE_ACCEPT received
[2023-07-23 13:11:50] debug3: send packet: type 50
[2023-07-23 13:11:50] debug3: receive packet: type 51
[2023-07-23 13:11:50] debug1: Authentications that can continue: publickey,password
[2023-07-23 13:11:50] debug3: start over, passed a different list publickey,password
[2023-07-23 13:11:50] debug3: preferred publickey,keyboard-interactive,password
[2023-07-23 13:11:50] debug3: authmethod_lookup publickey
[2023-07-23 13:11:50] debug3: remaining preferred: keyboard-interactive,password
[2023-07-23 13:11:50] debug3: authmethod_is_enabled publickey
[2023-07-23 13:11:50] debug1: Next authentication method: publickey
[2023-07-23 13:11:50] debug1: Offering public key: /Users/myuser/.ssh/id_rsa RSA SHA256:Mh8uuwZwf0zVhPGPmZ/i7SVHlikZmAleGnj9kphNMts
[2023-07-23 13:11:50] debug3: send packet: type 50
[2023-07-23 13:11:50] debug2: we sent a publickey packet, wait for reply
[2023-07-23 13:11:50] debug3: receive packet: type 60
[2023-07-23 13:11:50] debug1: Server accepts key: /Users/myuser/.ssh/id_rsa RSA SHA256:Mh8uuwZwf0zVhPGPmZ/i7SVHlikZmAleGnj9kphNMts
[2023-07-23 13:11:50] debug3: sign_and_send_pubkey: using publickey with RSA SHA256:Mh8uuwZwf0zVhPGPmZ/i7SVHlikZmAleGnj9kphNMts
[2023-07-23 13:11:50] debug3: sign_and_send_pubkey: signing using rsa-sha2-512 SHA256:Mh8uuwZwf0zVhPGPmZ/i7SVHlikZmAleGnj9kphNMts
[2023-07-23 13:11:50] debug3: send packet: type 50
[2023-07-23 13:11:50] debug3: receive packet: type 52
[2023-07-23 13:11:50] Authenticated to 11.22.33.44 ([11.22.33.44]:22) using "publickey".
[2023-07-23 13:11:50] debug1: channel 0: new [client-session]
[2023-07-23 13:11:50] debug3: ssh_session2_open: channel_new: 0
[2023-07-23 13:11:50] debug2: channel 0: send open
[2023-07-23 13:11:50] debug3: send packet: type 90
[2023-07-23 13:11:50] debug1: Requesting [email protected]
[2023-07-23 13:11:50] debug3: send packet: type 80
[2023-07-23 13:11:50] debug1: Entering interactive session.
[2023-07-23 13:11:50] debug1: pledge: filesystem
============================================================> THIS LASTS TWO MINUTES !!!
[2023-07-23 13:13:50] debug3: receive packet: type 80
[2023-07-23 13:13:50] debug1: client_input_global_request: rtype [email protected] want_reply 0
[2023-07-23 13:13:50] debug3: client_input_hostkeys: received RSA key SHA256:x3QJpmRsaVtBUPsVK4OQvBEmEJsIMwIEaAaXFponAbE
[2023-07-23 13:13:50] debug3: client_input_hostkeys: received DSA key SHA256:5TYE3nLbnFw6+nlaf3uqdhigRuvxIhDCY1fYuojmS/E
[2023-07-23 13:13:50] debug3: client_input_hostkeys: ssh-dss key not permitted by HostkeyAlgorithms
[2023-07-23 13:13:50] debug3: client_input_hostkeys: received ECDSA key SHA256:0dSYFvhEjytSvHdUYQdPFsuxuW8P4p1LzCytns1g+p4
[2023-07-23 13:13:50] debug3: client_input_hostkeys: received ED25519 key SHA256:GOn/fInx0w2m4ZjSkQGH5+lvgHtWdYAiF/uGiSaPh1Q
[2023-07-23 13:13:50] debug1: client_input_hostkeys: searching /Users/myuser/.ssh/known_hosts for 11.22.33.44 / (none)
[2023-07-23 13:13:50] debug3: hostkeys_foreach: reading file "/Users/myuser/.ssh/known_hosts"
[2023-07-23 13:13:50] debug3: hostkeys_find: found ecdsa-sha2-nistp256 key at /Users/myuser/.ssh/known_hosts:3
[2023-07-23 13:13:50] debug3: hostkeys_find: found ecdsa-sha2-nistp256 key under different name/addr at /Users/myuser/.ssh/known_hosts:4
[2023-07-23 13:13:50] debug3: hostkeys_find: found ecdsa-sha2-nistp256 key under different name/addr at /Users/myuser/.ssh/known_hosts:98
[2023-07-23 13:13:50] debug3: hostkeys_find: found ssh-ed25519 key under different name/addr at /Users/myuser/.ssh/known_hosts:118
[2023-07-23 13:13:51] debug1: client_input_hostkeys: searching /Users/myuser/.ssh/known_hosts2 for 11.22.33.44 / (none)
[2023-07-23 13:13:51] debug3: hostkeys_foreach: reading file "/Users/myuser/.ssh/known_hosts2"
[2023-07-23 13:13:51] debug3: client_input_hostkeys: 3 server keys: 2 new, 18446744073709551615 retained, 2 incomplete match. 0 to remove
[2023-07-23 13:13:51] debug1: client_input_hostkeys: host key found matching a different name/address, skipping UserKnownHostsFile update
[2023-07-23 13:13:51] debug3: receive packet: type 4
[2023-07-23 13:13:51] debug1: Remote: /root/.ssh/authorized_keys:3: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
[2023-07-23 13:13:51] debug3: receive packet: type 4
[2023-07-23 13:13:51] debug1: Remote: /root/.ssh/authorized_keys:3: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
[2023-07-23 13:13:51] debug3: receive packet: type 91
[2023-07-23 13:13:51] debug2: channel_input_open_confirmation: channel 0: callback start
[2023-07-23 13:13:51] debug2: fd 3 setting TCP_NODELAY
[2023-07-23 13:13:51] debug3: set_sock_tos: set socket 3 IP_TOS 0x20
[2023-07-23 13:13:51] debug2: client_session2_setup: id 0
[2023-07-23 13:13:51] debug1: Sending environment.
[2023-07-23 13:13:51] debug3: Ignored env TERM_PROGRAM
[2023-07-23 13:13:51] debug3: Ignored env SHELL
[2023-07-23 13:13:51] debug3: Ignored env TERM
[2023-07-23 13:13:51] debug3: Ignored env TMPDIR
[2023-07-23 13:13:51] debug3: Ignored env TERM_PROGRAM_VERSION
[2023-07-23 13:13:51] debug3: Ignored env TERM_SESSION_ID
[2023-07-23 13:13:51] debug3: Ignored env USER
[2023-07-23 13:13:51] debug3: Ignored env SSH_AUTH_SOCK
[2023-07-23 13:13:51] debug3: Ignored env PATH
[2023-07-23 13:13:51] debug3: Ignored env LaunchInstanceID
[2023-07-23 13:13:51] debug3: Ignored env __CFBundleIdentifier
[2023-07-23 13:13:51] debug3: Ignored env PWD
[2023-07-23 13:13:51] debug3: Ignored env XPC_FLAGS
[2023-07-23 13:13:51] debug3: Ignored env XPC_SERVICE_NAME
[2023-07-23 13:13:51] debug3: Ignored env SHLVL
[2023-07-23 13:13:51] debug3: Ignored env HOME
[2023-07-23 13:13:51] debug3: Ignored env LOGNAME
[2023-07-23 13:13:51] debug3: Ignored env SECURITYSESSIONID
[2023-07-23 13:13:51] debug3: Ignored env OLDPWD
[2023-07-23 13:13:51] debug3: Ignored env EDITOR
[2023-07-23 13:13:51] debug3: Ignored env TESSDATA_PREFIX
[2023-07-23 13:13:51] debug3: Ignored env LDFLAGS
[2023-07-23 13:13:51] debug3: Ignored env CPPFLAGS
[2023-07-23 13:13:51] debug3: Ignored env PKG_CONFIG_PATH
[2023-07-23 13:13:51] debug3: Ignored env LE_WORKING_DIR
[2023-07-23 13:13:51] debug3: Ignored env GUILE_LOAD_PATH
[2023-07-23 13:13:51] debug3: Ignored env GUILE_LOAD_COMPILED_PATH
[2023-07-23 13:13:51] debug3: Ignored env GUILE_SYSTEM_EXTENSIONS_PATH
[2023-07-23 13:13:51] debug3: Ignored env HOMEBREW_NO_AUTO_UPDATE
[2023-07-23 13:13:51] debug3: Ignored env AUTOJUMP_SOURCED
[2023-07-23 13:13:51] debug3: Ignored env AUTOJUMP_ERROR_PATH
[2023-07-23 13:13:51] debug1: channel 0: setting env LC_CTYPE = "UTF-8"
[2023-07-23 13:13:51] debug2: channel 0: request env confirm 0
[2023-07-23 13:13:51] debug3: send packet: type 98
[2023-07-23 13:13:51] debug3: Ignored env _
[2023-07-23 13:13:51] debug3: Ignored env __CF_USER_TEXT_ENCODING
[2023-07-23 13:13:51] debug1: Sending command: exit
[2023-07-23 13:13:51] debug2: channel 0: request exec confirm 1
[2023-07-23 13:13:51] debug3: send packet: type 98
[2023-07-23 13:13:51] debug2: channel_input_open_confirmation: channel 0: callback done
[2023-07-23 13:13:51] debug2: channel 0: open confirm rwindow 0 rmax 32768
[2023-07-23 13:13:51] debug2: channel 0: rcvd adjust 2097152
[2023-07-23 13:13:51] debug3: receive packet: type 99
[2023-07-23 13:13:51] debug2: channel_input_status_confirm: type 99 id 0
[2023-07-23 13:13:51] debug2: exec request accepted on channel 0
[2023-07-23 13:13:51] debug3: receive packet: type 96
[2023-07-23 13:13:51] debug2: channel 0: rcvd eof
[2023-07-23 13:13:51] debug2: channel 0: output open -> drain
[2023-07-23 13:13:51] debug2: channel 0: obuf empty
[2023-07-23 13:13:51] debug2: chan_shutdown_write: channel 0: (i0 o1 sock -1 wfd 5 efd 6 [write])
[2023-07-23 13:13:51] debug2: channel 0: output drain -> closed
[2023-07-23 13:13:51] debug3: receive packet: type 98
[2023-07-23 13:13:51] debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
[2023-07-23 13:13:51] debug3: receive packet: type 98
[2023-07-23 13:13:51] debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
[2023-07-23 13:13:51] debug2: channel 0: rcvd eow
[2023-07-23 13:13:51] debug2: chan_shutdown_read: channel 0: (i0 o3 sock -1 wfd 4 efd 6 [write])
[2023-07-23 13:13:51] debug2: channel 0: input open -> closed
[2023-07-23 13:13:51] debug3: receive packet: type 97
[2023-07-23 13:13:51] debug2: channel 0: rcvd close
[2023-07-23 13:13:51] debug3: channel 0: will not send data after close
[2023-07-23 13:13:51] debug2: channel 0: almost dead
[2023-07-23 13:13:51] debug2: channel 0: gc: notify user
[2023-07-23 13:13:51] debug2: channel 0: gc: user detached
[2023-07-23 13:13:51] debug2: channel 0: send close
[2023-07-23 13:13:51] debug3: send packet: type 97
[2023-07-23 13:13:51] debug2: channel 0: is dead
[2023-07-23 13:13:51] debug2: channel 0: garbage collecting
[2023-07-23 13:13:51] debug1: channel 0: free: client-session, nchannels 1
[2023-07-23 13:13:51] debug3: channel 0: status: The following connections are open:
[2023-07-23 13:13:51] #0 client-session (t4 r0 i3/0 o3/0 e[write]/0 fd -1/-1/6 sock -1 cc -1 io 0x00/0x00)
[2023-07-23 13:13:51]
[2023-07-23 13:13:51] debug3: send packet: type 1
[2023-07-23 13:13:51] Transferred: sent 2720, received 3292 bytes, in 120.3 seconds
[2023-07-23 13:13:51] Bytes per second: sent 22.6, received 27.4
[2023-07-23 13:13:51] debug1: Exit status 0
大约在这个时候,我在服务器上发现了/var/log/auth.log
:
Jul 23 13:14:58 ssh systemd-logind[525]: New session 3487137 of user root.
Jul 23 13:15:01 ssh CRON[733935]: pam_unix(cron:session): session opened for user root by (uid=0)
Jul 23 13:15:01 ssh CRON[733935]: pam_unix(cron:session): session closed for user root
Jul 23 13:16:58 ssh sshd[733933]: pam_systemd(sshd:session): Failed to create session: Connection timed out
Jul 23 13:18:01 ssh CRON[734044]: pam_unix(cron:session): session opened for user root by (uid=0)
Jul 23 13:18:01 ssh CRON[734044]: pam_unix(cron:session): session closed for user root
Jul 23 13:21:01 ssh CRON[734119]: pam_unix(cron:session): session opened for user root by (uid=0)
服务器上的配置文件如下所示:
root@ssh:~# cat /etc/ssh/sshd_config
# Package generated configuration file
# See the sshd_config(5) manpage for details
# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024
# Logging
SyslogFacility AUTH
LogLevel INFO
# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes
# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes
# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no
#MaxStartups 10:30:60
#Banner /etc/issue.net
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
# AllowUsers root
GatewayPorts yes
答案1
线路
Jul 23 13:16:58 ssh sshd[733933]: pam_systemd(sshd:session): Failed to create session: Connection timed out
是发生延迟的地方。系统正在等待创建 logind 会话,但最终超时,无法继续执行其他所有操作。您只需重新启动 systemd-logind 服务:
systemctl restart systemd-logind
然后,如果没有其他问题,连接应该会再次快速建立。