ubuntu - 虚拟盒子 : Port Forwarding for SSH from Win10 Host to Ubuntu Guest Stopped Working

标签 ubuntu virtualbox portforwarding

从我的 Windows 10 主机到我的 Ubuntu Virtual Box guest 的端口转发已经运行了三年多,然后在昨天 guest 重新启动后 PUTTY 突然停止连接。

我没有更改任何设置,它只是停止工作了。我已经调查并尝试了很多我在互联网上找到的建议,但它仍然无法正常工作。以下是详细信息:

在 Ubuntu 客户机上,我已确认 sshd 守护进程正在运行

$ ps aux | grep sshd
jryan    19096  0.0  0.0  61376  3036 ?    Ss  14:15  0:00 /usr/sbin/sshd

在 Ubuntu 客户机上,我可以通过 SSH 成功连接到端口 22 上的本地主机

$ ssh localhost
jryan@localhost's password:
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-108-generic x86_64)
...

在 Ubuntu 客户机上,我已确认 sshd 正在监听端口 22

netstat -lp --inet
tcp    0    0 localhost:ssh       *:*     LISTEN
tcp    0    0 10.0.0.18:ssh       *:*     LISTEN

同样,使用 nmap

$ sudo nmap -sS -O localhost/24
PORT      STATE SERVICE
22/tcp    open  ssh

当我从 Windows 10 主机(使用 Putty)进行 ssh 时,它只挂起 60 秒,然后我收到错误“服务器意外关闭网络连接”。然后我打开了一个 Windows BASH session 以从命令行运行 ssh:

jryan@JIMSURFACEPRO4:/mnt/c/Windows/System32$ ssh -vv jryan@127.0.0.1 -p 60022
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 60022.
debug1: Connection established.
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_rsa type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_rsa-cert type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_dsa type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_dsa-cert type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_ecdsa type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_ecdsa-cert type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_ed25519 type -1
debug1: identity file /mnt/c/Users/[user]/Google Drive/[user]/home/jryan/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
ssh_exchange_identification: Connection closed by remote host

我已确认在虚拟机上正确设置了端口转发:

VBoxManage showvminfo
NIC 2:           MAC: 080027775E38, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 2 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 2 Rule(0):   name = ssh, protocol = tcp, host ip = , host port = 60022, guest ip = , guest port = 22

我已经确认60022端口在Windows主机上是开放的

c:\Program Files\Oracle\VirtualBox>netstat -a

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:22             JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:80             JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:135            JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:443            JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:445            JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:7680           JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:23367          JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:49664          JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:49665          JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:49666          JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:49667          JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:49668          JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:49670          JimSurfacePro4:0       LISTENING
  TCP    0.0.0.0:60022          JimSurfacePro4:0       LISTENING
  TCP    10.0.0.8:139           JimSurfacePro4:0       LISTENING

我已经设置了 Windows 防火墙规则,允许端口 60022 上的所有 TCP 连接(入站和出站)

我检查了 Ubuntu 客户机上的日志。当我尝试连接时,/var/logs/auth.log/var/logs/syslog 中没有任何内容。

这是我在 Ubuntu 主机上的 /etc/ssh/sshd_config:

jryan@medstro-dev-jim:~$ cat /etc/ssh/sshd_config
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
ListenAddress 127.0.0.1
ListenAddress 10.0.0.18
Protocol 2,1
AllowUsers jryan
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
PasswordAuthentication yes
LoginGraceTime 240
PermitRootLogin without-password
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
ClientAliveInterval 60
ClientAliveCountMax 20
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

我没主意了。如果您能弄清楚这里发生了什么,请告诉我。

谢谢!

最佳答案

关闭windows防火墙试一次。在 Windows 10 中,我观察到虚拟盒子网络存在一些问题。

关于ubuntu - 虚拟盒子 : Port Forwarding for SSH from Win10 Host to Ubuntu Guest Stopped Working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42045863/

相关文章:

java - Intellij Checkstyle 给出错误 NoClassDefFoundError

c# - Web API 自托管公共(public) IP

linux - 如何在 Linux 中设置 i2c 总线的波特率?

opencv - 在 ubuntu 14.04 LTS 中安装 opencv 2.4.10 时出现未定义的引用错误

virtualbox - Vagrant 端口转发不适用于 Fedora 20 上的虚拟主机

macos - 在 Mac 上解压缩大型 ZIP 文件(如最新的 Microsoft Edge VM)

python - 如何使用python从虚拟机读取文件

Kubernetes 端口转发 - 连接被拒绝

java - 需要java套接字中的端口转发帮助(带AWS服务器的AWS CISCO路由器)

ubuntu - 从 ubuntu 中的 C++ 代码向 arduino 发送命令