To setup a ssh server on your linux VM in WSL2 on windows

From https://www.brianketelsen.com/blog/ssh-to-wsl2/

  • In the WSL2 system setup ssh to your liking and turn it on
service ssh start
systemctl enable ssh
  • In Power Shell, enable the port forwarding (subbing in your VMs IP (ifconfig)):

netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=2222 connectaddress=172.19.149.102

  • In Windows Defender Firewall, allow port 22