我有两台笔记本电脑 [L1、L2] 连接到同一个盒子,均使用 Debian 11:
- 一级:通过以太网连接,无线网卡开启
- 二级:仅通过 WiFi 连接
使用此配置,我无法使用 SSH 将 L1 [客户端] 连接到 L2 [服务器],如果我想使用 SSH,我必须断开 L1 的以太网电缆或关闭 L1 的 WiFi,我想了解原因:
- 客户:
~$ ip -brief addr lo UNKNOWN 127.0.0.1/8 ::1/128 enp1s0f1 UP 192.168.1.24/24 fe80::id1 wlp2s0 UP 192.168.1.24/24 fe80::id2
~$ ssh -vvv [email protected] OpenSSH_8.4p1 Debian-5+deb11u1, OpenSSL 1.1.1n 15 Mar 2022 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files debug1: /etc/ssh/ssh_config line 21: Applying options for * debug2: resolve_canonicalize: hostname 192.168.1.21 is address debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/xxx/.ssh/known_hosts' debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/xxx/.ssh/known_hosts2' debug2: ssh_connect_direct debug1: Connecting to 192.168.1.21 [192.168.1.21] port 22. debug1: connect to address 192.168.1.21 port 22: No route to host ssh: connect to host 192.168.1.21 port 22: No route to host
- 服务器:
~# /usr/sbin/sshd -d debug1: sshd version OpenSSH_9.2, OpenSSL 3.0.9 30 May 2023 debug1: private host key #0: ssh-rsa debug1: private host key #1: ecdsa-sha2-nistp256 debug1: private host key #2: ssh-ed25519 debug1: rexec_argv[0]='/usr/sbin/sshd' debug1: rexec_argv[1]='-d' debug1: Set /proc/self/oom_score_adj from 0 to -1000 debug1: Bind to port 22 on 0.0.0.0. Server listening on 0.0.0.0 port 22. debug1: Bind to port 22 on ::. Server listening on :: port 22. debug1: Server will not fork when running in debugging mode. debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8 debug1: sshd version OpenSSH_9.2, OpenSSL 3.0.9 30 May 2023 debug1: private host key #0: ssh-rsa SHA256: debug1: private host key #1: ecdsa-sha2-nistp256 SHA256: debug1: private host key #2: ssh-ed25519 SHA256: debug1: inetd sockets after dupping: 3, 3 Connection from 192.168.1.24 port 36154 on 192.168.1.21 port 22 rdomain "" debug1: Local version string SSH-2.0-OpenSSH_9.2p1 Debian-2 debug1: Remote protocol version 2.0, remote software version OpenSSH_8.4p1 Debian-5+deb11u1 debug1: compat_banner: match: OpenSSH_8.4p1 Debian-5+deb11u1 pat OpenSSH* compat 0x04000000 debug1: permanently_set_uid: 115/65534 [preauth] debug1: list_hostkey_types: rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519 [preauth] debug1: SSH2_MSG_KEXINIT sent [preauth] debug1: SSH2_MSG_KEXINIT received [preauth] debug1: kex: algorithm: curve25519-sha256 [preauth] debug1: kex: host key algorithm: ecdsa-sha2-nistp256 [preauth] debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none [preauth] debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none [preauth] debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth] debug1: SSH2_MSG_KEX_ECDH_INIT received [preauth] debug1: rekey out after 134217728 blocks [preauth] debug1: SSH2_MSG_NEWKEYS sent [preauth] debug1: Sending SSH2_MSG_EXT_INFO [preauth] debug1: expecting SSH2_MSG_NEWKEYS [preauth] debug1: SSH2_MSG_NEWKEYS received [preauth] debug1: rekey in after 134217728 blocks [preauth] debug1: KEX done [preauth] debug1: userauth-request for user xxx service ssh-connection method none [preauth] debug1: attempt 0 failures 0 [preauth] debug1: PAM: initializing for "xxx" debug1: PAM: setting PAM_RHOST to "192.168.1.24" debug1: PAM: setting PAM_TTY to "ssh" debug1: userauth_send_banner: sent [preauth] debug1: userauth-request for user xxx service ssh-connection method publickey [preauth] debug1: attempt 1 failures 0 [preauth] debug1: userauth_pubkey: publickey test pkalg rsa-sha2-512 pkblob RSA SHA256:[preauth] debug1: temporarily_use_uid: 1000/1000 (e=0/0) debug1: trying public key file /home/mi/.ssh/authorized_keys debug1: fd 4 clearing O_NONBLOCK debug1: /home/xxx/.ssh/authorized_keys:1: matching key found: RSA SHA256: debug1: /home/xxx/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding Accepted key RSA SHA256: found at /home/xxx/.ssh/authorized_keys:1 debug1: restore_uid: 0/0 Postponed publickey for xxx from 192.168.1.24 port 36154 ssh2 [preauth] debug1: userauth-request for user xxx service ssh-connection method publickey [preauth] debug1: attempt 2 failures 0 [preauth] debug1: temporarily_use_uid: 1000/1000 (e=0/0) debug1: trying public key file /home/xxx/.ssh/authorized_keys debug1: fd 4 clearing O_NONBLOCK debug1: /home/xxx/.ssh/authorized_keys:1: matching key found: RSA SHA256: debug1: /home/xxx/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding Accepted key RSA SHA256: found at /home/xxx/.ssh/authorized_keys:1 debug1: restore_uid: 0/0 debug1: auth_activate_options: setting new authentication options debug1: do_pam_account: called Accepted publickey for xxx from 192.168.1.24 port 36154 ssh2: RSA SHA256: debug1: monitor_child_preauth: user xxx authenticated by privileged process debug1: auth_activate_options: setting new authentication options [preauth] debug1: monitor_read_log: child log fd closed debug1: PAM: establishing credentials User child is on pid 2553 debug1: SELinux support disabled debug1: PAM: establishing credentials debug1: permanently_set_uid: 1000/1000 debug1: rekey in after 134217728 blocks debug1: rekey out after 134217728 blocks debug1: ssh_packet_set_postauth: called debug1: active: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding debug1: Entering interactive session for SSH2. debug1: server_init_dispatch debug1: server_input_channel_open: ctype session rchan 0 win 1048576 max 16384 debug1: input_session_request debug1: channel 0: new session [server-session] (inactive timeout: 0) debug1: session_new: session 0 debug1: session_open: channel 0 debug1: session_open: session 0: link with channel 0 debug1: server_input_channel_open: confirm session debug1: server_input_global_request: rtype [email protected] want_reply 0 debug1: server_input_channel_req: channel 0 request pty-req reply 1 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req pty-req debug1: Allocating pty. debug1: session_new: session 0 debug1: SELinux support disabled debug1: session_pty_req: session 0 alloc /dev/pts/1 debug1: server_input_channel_req: channel 0 request env reply 0 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req env debug1: server_input_channel_req: channel 0 request shell reply 1 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req shell Starting session: shell on pts/1 for xxx from 192.168.1.24 port 36154 id 0
答案1
问题通过日志和网络设置更新后修改的答案:
在客户端L1,两个网卡、以太网和 WiFi 都分配了相同的 IP。
分配不同的 IP 后,问题就消失了。
获取调试日志:
- 退出所有打开的 SSH 会话
- 停止
sshd
,然后使用调试详细程度重新启动它:# Get the PID for sshd' and terminate it: ps ax | sudo sed -En 's|^\s*([0-9]+)\s.*/usr/sbin/ssh[d].*$|kill \1|pe' # Verify success (sshd processes should show up): ps ax | grep "ssh[d]" # Start sshd with debug option, then print output to screen and file: sudo /usr/sbin/sshd -d | tee your_debug.log # For debug verbosity on the client, call ssh with <-v || -vv || -vvv>: # -v: Debug1 || -vv: Debug2 | -vvv: Debug3: ssh -v <parameters>
- 启用调试后,
sshd
输出到终端并your_debug.log