SSH into WSL2 on windows

I have playing with WSL2 (Ubuntu 24.04) and toying with idea maybe it can become my primary linux dev environment and replace the cumbersome vmware player setup. One hiccup I had yesterday was that I could not ssh into wsl2. And apparently even with powerful AI agent (Gemini in this case) I couldn’t get it resolved until this morning.

The Laptop

  • It is running Windows 11 Home Edition. As a result hyper-V is based solution is not available, specifically the bridged networking mode is not availabe.
  • I used the mirrored networking mode.

The Key to Success

  1. add hyper-v firewall to allow incoming traffic, New-NetFirewallHyperVRule -Name "Allow WSL SSH" -DisplayName "Allow WSL SSH" -Direction Inbound -Protocol TCP -LocalPorts 22 -Action Allow
  2. Add the following lines to .wslconfig file
[experimental]
hostAddressLoopback=true

After that, you will need to shutdown wsl2 and restart it, wsl --shutdown .

Below is the complete copy of my wslconfig file:

[wsl2]
networkingMode=mirrored
processors=16
memory=24GB
nestedVirtualization=true

[experimental]
hostAddressLoopback=true

Leave a Reply