SSH 到我的服务器失败

SSH 到我的服务器失败

假设我的服务器有“我的”IP。客户端是一台 Linux(Debian)机器,IP 为 192.168.15.120。我尝试从同一子网中的另一台机器(Windows)进行连接,IP 为 192.168.15.106。“我的”是互联网上的服务器,IP 为 195.xxx.xxx.xxx(肯定在 LAN 之外)。Windows 机器可以 ssh 到我的,而我(Linux 客户端)则不能。当我在服务器上将 ssh 端口更改为 7822 时,我的客户端可以 ssh 到它。似乎我的客户端上的端口 22 出了问题。你的看法是什么?我该如何追踪问题并找到它?

更新:

运行 ssh -v my 后我得到以下输出:

debug1: Reading configuration data /home/hamidi/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to my [195.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /home/hamidi/.ssh/id_rsa type 0
debug1: identity file /home/hamidi/.ssh/id_rsa-cert type -1
debug1: identity file /home/hamidi/.ssh/id_dsa type -1
debug1: identity file /home/hamidi/.ssh/id_dsa-cert type -1
debug1: identity file /home/hamidi/.ssh/id_ecdsa type -1
debug1: identity file /home/hamidi/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/hamidi/.ssh/id_ed25519 type -1
debug1: identity file /home/hamidi/.ssh/id_ed25519-cert type -1
debug1: identity file /home/hamidi/.ssh/id_xmss type -1
debug1: identity file /home/hamidi/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9p1 Debian-10+deb10u2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.8
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.8 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to my:22 as 'hamidi'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:GLEbQGgsPG4q1m5NpQpx1qgfGH+niS93ZQqz/m+amIM
The authenticity of host 'my (195.xxx.xxx.xxx)' can't be established.
RSA key fingerprint is SHA256:GLEbQGgsPG4q1m5NpQpx1qgfGH+niS93ZQqz/m+amIM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'my,195.xxx.xxx.xxx' (RSA) to the list of known hosts.
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: Will attempt key: /home/hamidi/.ssh/id_rsa RSA SHA256:XPZJP0PUv/cEg+Z0tsDL6sm8aTEkl/vt+ewJt/RwwH8 agent
debug1: Will attempt key: /home/hamidi/.ssh/id_dsa 
debug1: Will attempt key: /home/hamidi/.ssh/id_ecdsa 
debug1: Will attempt key: /home/hamidi/.ssh/id_ed25519 
debug1: Will attempt key: /home/hamidi/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/hamidi/.ssh/id_rsa RSA SHA256:XPZJP0PUv/cEg+Z0tsDL6sm8aTEkl/vt+ewJt/RwwH8 agent
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/hamidi/.ssh/id_dsa
debug1: Trying private key: /home/hamidi/.ssh/id_ecdsa
debug1: Trying private key: /home/hamidi/.ssh/id_ed25519
debug1: Trying private key: /home/hamidi/.ssh/id_xmss
debug1: Next authentication method: password
hamidi@my's password: 
debug1: Authentication succeeded (password).
Authenticated to my ([195.xxx.xxx.xxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-184-generic x86_64)
...

答案1

在 Linux 中调试 ssh 问题的最大工具可能是ssh -v <ip>ssh -vv <ip>。您还可以将其与切换端口结合起来,因为您提到您在默认端口上遇到了问题,例如:ssh -v -p 7822 <ip>

编辑:正如评论中提到的,你可能需要查看服务器上的 sshd 日志,该日志通常位于 ubuntu/debian 的 /var/log/auth.log 中,当你无法连接时,也许可以实时跟踪日志tail -f /var/log/auth.log

相关内容