为什么我不能再通过 SSH 进入我的 Ubuntu VM?

为什么我不能再通过 SSH 进入我的 Ubuntu VM?

我有几个基于 Debian 的 Linux 发行版,它们在 Windows 10 上的 VMware Workstation Player 上运行。我以前能够从主机通过 PowerShell 或 Ubuntu (WSL) 终端通过 SSH 连接到虚拟机,没有任何问题。但最近我无法这样做了。

首先我在虚拟机上启动 SSH 服务。

service ssh start

然后我验证该服务是否正在运行。

service ssh status
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: e>
     Active: active (running) since Sat 2021-06-26 11:30:42 PDT; 1min 14s ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 872 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
   Main PID: 898 (sshd)
      Tasks: 1 (limit: 9448)
     Memory: 2.8M
     CGroup: /system.slice/ssh.service
             └─898 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

Jun 26 11:30:42 ubuntu systemd[1]: Starting OpenBSD Secure Shell server...
Jun 26 11:30:42 ubuntu sshd[898]: Server listening on 0.0.0.0 port 22.
Jun 26 11:30:42 ubuntu sshd[898]: Server listening on :: port 22.
Jun 26 11:30:42 ubuntu systemd[1]: Started OpenBSD Secure Shell server.

我验证了 IP 地址。

hostname -I
192.168.75.129

ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:a0:15:34 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 192.168.75.129/24 brd 192.168.75.255 scope global dynamic noprefixroute ens33
       valid_lft 1714sec preferred_lft 1714sec
    inet6 fe80::98eb:dd0a:da24:92be/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

...但 Windows Subsystem for Linux 上的 Ubuntu 无法连接。

ssh 192.168.75.129
ssh -vvv 192.168.75.129
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020
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.75.129 is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.75.129 [192.168.75.129] port 22.
debug1: connect to address 192.168.75.129 port 22: Resource temporarily unavailable
ssh: connect to host 192.168.75.129 port 22: Resource temporarily unavailable

...并且 PowerShell 超时。

ssh -vvv 192.168.75.129
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug3: Failed to open file:C:/Users/me/.ssh/config error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolve_canonicalize: hostname 192.168.75.129 is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.75.129 [192.168.75.129] port 22.
debug3: finish_connect - ERROR: async io completed with error: 10060, io:000001B003450380
debug1: connect to address 192.168.75.129 port 22: Connection timed out
ssh: connect to host 192.168.75.129 port 22: Connection timed out

NMAP 返回以下扫描。

nmap -Pn -p 22 192.168.75.129
Warning: Nmap may not work correctly on Windows Subsystem for Linux.
For best performance and accuracy, use the native Windows build from https://nmap.org/download.html#windows.
Starting Nmap 7.80 ( https://nmap.org ) at 2021-06-26 13:36 CDT
NSOCK ERROR [0.0460s] mksock_bind_device(): Setting of SO_BINDTODEVICE failed (IOD #1): Protocol not available (92)
NSOCK ERROR [0.0470s] mksock_bind_device(): Setting of SO_BINDTODEVICE failed (IOD #2): Protocol not available (92)
NSOCK ERROR [0.0470s] mksock_bind_device(): Setting of SO_BINDTODEVICE failed (IOD #3): Protocol not available (92)
Problem binding to interface , errno: 92
socket_bindtodevice: Protocol not available
Problem binding to interface , errno: 92
socket_bindtodevice: Protocol not available
Nmap scan report for 192.168.75.129
Host is up.

PORT   STATE    SERVICE
22/tcp filtered ssh

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

...以及来自 Windows 上的 nmap。

PS C:\Users\me> cd '\Program Files (x86)\nmap'
PS C:\Program Files (x86)\nmap> ./nmap.exe -Pn -p 22 192.168.75.129
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
WARNING: Could not import all necessary Npcap functions. You may need to upgrade to the latest version from https://npcap.org. Resorting to connect() mode -- Nmap may not function completely
Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-26 13:36 Central Daylight Time
Nmap scan report for 192.168.75.129
Host is up.

PORT   STATE    SERVICE
22/tcp filtered ssh

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

我究竟做错了什么?

答案1

问题肯定出在主机上的 VMware Workstation 16 Player 上。我重新安装了 VMware Workstation,它又开始工作了。

答案2

我遇到了你的问题,最后我通过在网络和互联网设置中禁用所有 vmware 网络适配器解决了它。所以这样做:

  1. 在 Windows 中转到控制面板\网络和 Internet\网络连接
  2. 禁用所有 VMware 适配器
  3. 再次启用它们
  4. 测试你的 ssh 和 ping,享受它!

答案3

打开窗口设置:

  1. 单击网络 _&Internet。
  2. 选择更改网络选项。
  3. 禁用任何 VMware 网络适配器并再次启用它们。

如果您没有看到任何与 VMware 相关的内容,我建议您删除并再次安装 VMware。

相关内容