参考资料:https://github.com/ajithmoola/wsl-ssh-guide
首先,和正常配置
SSH Server一样,在WSL内配置好
这里有个建议,把端口改了,22端口暴露出去不知道会不会有权限的问题
端口映射:让我们能从外部连接到WSL内部,以下使用PowerShell (Admin)
wsl hostname -I (Get your WSL IP address)
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=2222 connectaddress=<WSL_IP_ADDRESS> (Set up port forwarding, 2222是之前设定的端口)
完成这一步之后呢,就可以在本机连接到WSL了(用localhost)
-
Open Windows Defender Firewall with Advanced Security.
Click on “Inbound Rules” and then “New Rule”.
Choose “Port” and click Next.
Select “TCP” and enter “2222” for the port number.
Allow the connection and apply the rule to all profiles.
Name the rule (e.g., “WSL SSH”) and finish the wizard.