1

I have a Windows 10 machine with WSL2 (running Ubuntu 22.04.1 LTS) and a Linux machine in the LAN of the Windows machine. I'm able to connect from the Windows host to the SSH server running in WSL. Now I want to connect to the WSL from the Linux machine or to the Linux machine from the WSL. Now according to this answer I ran the following command in PowerShell on my Windows system:

netsh interface portproxy add v4tov4 listenport=4000 listenaddress=0.0.0.0 connectport=4000 connectaddress=192.168.101.100

where 192.168.101.100 is the IP of the WSL. Then how do I SSH from the Linux machine directly to WSL? I tried ssh -p 4000 windowsHost@windowsAdress but it is not working:

#ssh -vvv -p 4000 windowsHost@windowsAdress
OpenSSH_6.7p1 Debian-5+deb8u8, OpenSSL 1.0.1t  3 May 2016
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 windowsAdress [windowsAdress] port 4000.

... and it is stuck there.

NotTheDr01ds
  • 28,025
roi_saumon
  • 111
  • 1
  • 6

1 Answers1

2

In your other question, you show your /etc/ssh/sshd_config with the SSH server running on the default port of 22. If this is the case, then you will need to adjust your port forwarding connectport to:

netsh interface portproxy add v4tov4 listenport=4000 listenaddress=0.0.0.0 connectport=22 connectaddress=192.168.101.100

This will forward connections from port 4000 on the Windows host to port 22 on the WSL2 host.

You may also need a firewall rule, as mentioned in the comments. However, you should typically receive a request from Windows Defender Firewall to allow the connection the first time you use it.

Keep in mind that you will have to adjust the connectaddress each time you reboot (or WSL2 restarts) because the IP address is dynamically assigned. It's also good practice to delete the old port-forwarding rules each time. For this reason, I find it easier to use SSH itself to handle the port forwarding. I won't repeat all the steps here, but you can find the details in "Option 2" of this answer.

NotTheDr01ds
  • 28,025