ssh:连接到主机 xxx.yyy.com 端口 22:连接被拒绝 - 无法通过 SSH 访问我的服务器

ssh:连接到主机 xxx.yyy.com 端口 22:连接被拒绝 - 无法通过 SSH 访问我的服务器

我使用的是 Ubuntu 22,SSH 处于活动状态。UFW 处于非活动状态。我有一个密钥对,并且已将 pub 存储在服务器上authorized_keys。我的另一台计算机上已经有密钥了。我在我的私有网络中。从这个网络,我可以通过 SSH 使用我的旧计算机访问服务器。

因此,您可能会认为所有设置都正确。特别是因为 SSH 的基本设置相对来说不言自明,而且作为初学者,我从未遇到过建立 SSH 连接的问题。

笔记:我可以使用相同的公钥访问我的 GitHub 帐户。因此密钥和我的 SSH 都可以正常工作。

问题:还有什么原因可能导致此错误?

SSH-vvvv[电子邮件保护]输出

OpenSSH_8.9p1 Ubuntu-3ubuntu0.6, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /home/me/.ssh/config
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 *
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/me/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/me/.ssh/known_hosts2'
debug2: resolving "xxx.yyy.com" port 22
debug3: resolve_host: lookup xxx.yyy.com:22
debug3: ssh_connect_direct: entering
debug1: Connecting to xxx.yyy.com [1.1.1.1] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x10
debug1: connect to address 1.1.1.1 port 22: Connection refused
ssh: connect to host xxx.yyy.com port 22: Connection refused

输出:systemctl status sshd.service

● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: e>
     Active: active (running) since Fri 2024-03-08 09:51:37 CET; 4h 42min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 2847372 (sshd)
      Tasks: 1 (limit: 18688)
     Memory: 1.7M
        CPU: 13ms
     CGroup: /system.slice/ssh.service
             └─2847372 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Mär 08 09:51:37 ttsbnb50 systemd[1]: Starting OpenBSD Secure Shell server...
Mär 08 09:51:37 ttsbnb50 sshd[2847372]: Server listening on 0.0.0.0 port 22.
Mär 08 09:51:37 ttsbnb50 sshd[2847372]: Server listening on :: port 22.
Mär 08 09:51:37 ttsbnb50 systemd[1]: Started OpenBSD Secure Shell server.

输出:sudo netstat -anp | grep ssh

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2847372/sshd: /usr/ 
tcp6       0      0 :::22                   :::*                    LISTEN      2847372/sshd: /usr/ 
unix  2      [ ACC ]     STREAM     HÖRT         42144    4471/systemd         /run/user/1000/gnupg/S.gpg-agent.ssh
unix  2      [ ACC ]     STREAM     HÖRT         43365    4493/gnome-keyring-  /run/user/1000/keyring/ssh
unix  3      [ ]         STREAM     VERBUNDEN     16223127 2847372/sshd: /usr/  
unix  2      [ ACC ]     STREAM     HÖRT         5563534  1563240/ssh-agent    /run/user/1000/keyring/.ssh

输出:ls -la ~/.ssh来自无法连接到我的服务器的计算机

drwx------  2 me me 4096 Mär  3 15:12 .
drwxr-x--- 32 me me 4096 Mär  8 14:42 ..
-rw-rw-r--  1 me me   51 Dez 29 22:48 config
-rw-------  1 me me  464 Apr 18  2023 id_ed25519
-rw-r--r--  1 me me  111 Apr 18  2023 id_ed25519.pub
-rw-------  1 me me 1784 Jan  8 10:27 known_hosts

输出:cat ~/.ssh/config

Host github.com
 Hostname ssh.github.com
 Port 443

输出:cat /etc/ssh/ssh_config | grep -v ^#

Include /etc/ssh/ssh_config.d/*.conf

Host *
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes

输出:ls -la /etc/ssh

drwxr-xr-x   4 root root   4096 Mär  8 09:51 .
drwxr-xr-x 143 root root  12288 Mär 12 06:25 ..
-rw-r--r--   1 root root 505426 Jan  2 17:54 moduli
-rw-r--r--   1 root root   1650 Nov 23  2022 ssh_config
drwxr-xr-x   2 root root   4096 Nov 23  2022 ssh_config.d
-rw-r--r--   1 root root   3254 Jan  2 17:54 sshd_config
drwxr-xr-x   2 root root   4096 Jan  2 17:54 sshd_config.d
-rw-------   1 root root    505 Mär  8 09:51 ssh_host_ecdsa_key
-rw-r--r--   1 root root    175 Mär  8 09:51 ssh_host_ecdsa_key.pub
-rw-------   1 root root    399 Mär  8 09:51 ssh_host_ed25519_key
-rw-r--r--   1 root root     95 Mär  8 09:51 ssh_host_ed25519_key.pub
-rw-------   1 root root   2602 Mär  8 09:51 ssh_host_rsa_key
-rw-r--r--   1 root root    567 Mär  8 09:51 ssh_host_rsa_key.pub
-rw-r--r--   1 root root    342 Dez  7  2020 ssh_import_id

输出:cat /etc/ssh/ssh_config

Host *
#   ForwardAgent no
#   ForwardX11 no
#   ForwardX11Trusted yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,[email protected]
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h
#   UserKnownHostsFile ~/.ssh/known_hosts.d/%k
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes

相关内容