In setting up SSH into an Linux install in WSL2, I’ve found guides on how to do this setup. While most contain the similar steps for setting up SSH, they have very different mechanisms for making it start on boot, of which almost none work.
Setting up SSH
First I’ll assume you are running WSL2 and have installed a debian based linux within it.
- Launch the WSL instance and inside it execute:
sudo apt install openssh-server
- Run
ip addr show
to get the IP address of this VM to be used later - Launch your favorite shell on the windows side and run:
and substitute the IP address you obtained earlier for thenetsh advfirewall firewall add rule name=”Open Port 2222 for WSL2” dir=in action=allow protocol=TCP localport=2222 netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=2222 connectaddress=172.23.129.80 connectport=22
connectaddress
in the second line. - Execute
netsh interface portproxy show v4tov4
to confirm it is set correctly (and you can runnetsh int portproxy reset all
to remove the entries if you need).
(A step or two may be missing above but this is the gist and I’m not trying to make a comprehensive guide for this part)