【问题标题】:Troubleshooting ssh "Connection timed out" with Linux for Windows subsystem使用 Linux for Windows 子系统对 ssh“连接超时”进行故障排除
【发布时间】:2021-07-22 16:50:37
【问题描述】:

我正在使用 Windows 10 教育版,我需要配置远程访问。

我成功安装了 WSL2、Ubuntu 20.04 并按照本教程进行操作 https://www.illuminiastudios.com/dev-diaries/ssh-on-windows-subsystem-for-linux/

现在我可以使用 myusername@Ipv4 进行本地连接。

但它在另一个桌面上不起作用:“port22:连接超时”。我尝试从两台使用 VPN 连接到同一网络的计算机。

我不知道如何调试。提前感谢您的帮助。

【问题讨论】:

  • 您确认 sshd 实际监听的是 0.0.0.0 而不是 127.0.0.1 或 ::1?我认为它会在 /etc/ssh/sshd_config 中指定
  • 是的,它正在收听127.0.0.1,所以我听从了jishi的建议! (谢谢)

标签: windows-subsystem-for-linux openssh wsl-2


【解决方案1】:

除了 sshd 配置不正确之外,我认为 WSL 和 WSL2 都只转发在 localhost 上侦听的端口,使远程连接无法访问它们(我在这里有类似的讨论)https://github.com/microsoft/WSL/discussions/4872#discussioncomment-76626

如果需要,您可以配置 netsh 为某些端口设置从 0.0.0.0(所有接口)到 localhost 的端口转发,但我不知道上面的语法。你可以在这里找到它的文档:

https://docs.microsoft.com/en-us/windows-server/networking/technologies/netsh/netsh-interface-portproxy

不过,请注意。 WSL2 将可以访问您的 Windows 文件系统,它不像普通的虚拟化那样工作。如果您允许其他人进入您的 WSL2 机器,他们将能够在某种程度上读写您的文件系统,这可能不是您想要的,并且通过 SSH 访问它很少是您想要的。

【讨论】:

  • 谢谢,它有效,我做到了 - netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=22 connectaddress=localhost connectport=22 - 并禁用了 Windows Defender 防火墙
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-16
  • 2014-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
相关资源
最近更新 更多