ssh 只有一种方式工作

ssh 只有一种方式工作

我有两台电脑,一台正在运行Debian GNU/Linux 9和另一个Ubuntu 18.04.1 LTS。我在两台电脑上都安装了openssh。

sudo apt install openssh-client
sudo apt install openssh-server

现在,我可以使用 ssh 从 Debian 连接到 Ubuntu,但不能从 Ubuntu 连接到 Debian。

在 Debian 计算机上

nmap localhost

输出:

Starting Nmap 7.40 ( https://nmap.org ) at 2019-01-24 14:39 CET
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00010s latency).
Other addresses for localhost (not scanned): ::1
Not shown: 999 closed ports
PORT   STATE SERVICE
22/tcp open  ssh

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds

我也尝试过跑步

sudo ufw allow ssh

在 Debian 计算机上。

我应该怎么做才能从另一台计算机访问另一台计算机?


已针对评论进行编辑

netstat -l在 Debian 服务器上运行输出:

b1012@debian:~$ netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 localhost:5939          0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN     
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN     
udp        0      0 0.0.0.0:mdns            0.0.0.0:*                          
udp        0      0 0.0.0.0:40272           0.0.0.0:*                          
udp        0      0 0.0.0.0:57967           0.0.0.0:*                          
udp        0      0 0.0.0.0:bootpc          0.0.0.0:*                          
udp6       0      0 [::]:mdns               [::]:*                             
udp6       0      0 [::]:41052              [::]:*                             
raw6       0      0 [::]:ipv6-icmp          [::]:*                  7          
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     19723    /run/user/1000/pulse/native
unix  2      [ ACC ]     STREAM     LISTENING     15627    /run/uuidd/request
unix  2      [ ACC ]     STREAM     LISTENING     15630    /var/run/avahi-daemon/socket
unix  2      [ ACC ]     STREAM     LISTENING     15633    /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     16129    /tmp/ssh-AYHltf8zzAuv/agent.600
unix  2      [ ACC ]     STREAM     LISTENING     16960    /tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     18495    /tmp/.ICE-unix/600
unix  2      [ ACC ]     STREAM     LISTENING     17542    @/tmp/dbus-0nAe1Vft
unix  2      [ ACC ]     STREAM     LISTENING     16959    @/tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     14138    @/tmp/dbus-kLaALJuH
unix  2      [ ACC ]     STREAM     LISTENING     18494    @/tmp/.ICE-unix/600
unix  2      [ ACC ]     STREAM     LISTENING     14179    /run/user/1000/systemd/private
unix  2      [ ACC ]     STREAM     LISTENING     14184    /run/user/1000/gnupg/S.gpg-agent.browser
unix  2      [ ACC ]     STREAM     LISTENING     14187    /run/user/1000/bus
unix  2      [ ACC ]     STREAM     LISTENING     14189    /run/user/1000/gnupg/S.gpg-agent
unix  2      [ ACC ]     STREAM     LISTENING     14191    /run/user/1000/gnupg/S.gpg-agent.extra
unix  2      [ ACC ]     STREAM     LISTENING     14193    /run/user/1000/gnupg/S.gpg-agent.ssh
unix  2      [ ACC ]     STREAM     LISTENING     17539    /run/user/1000/keyring/control
unix  2      [ ACC ]     SEQPACKET  LISTENING     1427     /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     14139    @/tmp/dbus-kLVeQt6a
unix  2      [ ACC ]     STREAM     LISTENING     17311    /run/user/1000/keyring/ssh
unix  2      [ ACC ]     STREAM     LISTENING     17313    /run/user/1000/keyring/pkcs11
unix  2      [ ACC ]     STREAM     LISTENING     9634     /run/systemd/private
unix  2      [ ACC ]     STREAM     LISTENING     9648     /run/systemd/journal/stdout
unix  2      [ ACC ]     STREAM     LISTENING     9653     /run/systemd/fsck.progress
unix  2      [ ACC ]     STREAM     LISTENING     17541    @/tmp/dbus-yMrL8O3f
unix  2      [ ACC ]     STREAM     LISTENING     18465    @/tmp/dbus-stZvWk5V9a
unix  2      [ ACC ]     STREAM     LISTENING     17404    /var/run/NetworkManager/private-dhcp

connection timed out尝试连接时,我得到了。

ssh [email protected] -vvv
OpenSSH_7.6p1 Ubuntu-4ubuntu0.1, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /home/optoscale/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "192.168.0.104" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.168.0.104 [192.168.0.104] port 22.
debug1: connect to address 192.168.0.104 port 22: Connection timed out
ssh: connect to host 192.168.0.104 port 22: Connection timed out

跑步

b1012@debian:~$ systemctl status ssh.service

输出:

● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
   Active: active (running) since Thu 2019-01-24 13:42:23 CET; 2h 0min ago
  Process: 3594 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCES
  Process: 3589 ExecReload=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Main PID: 2332 (sshd)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/ssh.service
           └─2332 /usr/sbin/sshd -D

答案1

您的两台计算机之间有 NAT 防火墙。您可以看到这一点,因为您的 Debian 系统的 IP 地址是 192.168.0.24,但 Ubuntu 系统看到来自 10.20.81.24 的关联入站连接。

除非您控制和管理此 NAT 防火墙,否则您将无法直接从 Ubuntu 服务器连接到 Debian 服务器。 (存在多种解决方法,包括autossh在 Debian 系统上运行反向隧道,或者从 Debian 启动到 Ubuntu 的 OpenVPN。两者都可以允许以另一种方式建立连接。)

相关内容