Install openssh-server¶
Handle Windows-side port forwarding¶
Run this in an elevated (Administrator) PowerShell prompt
Get the current WSL instance's IP address¶
$wslIp = wsl hostname -I
$wslIp = $wslIp.Trim().Split(" ")[0]
Remove any existing portproxy rule for this port (safe to run even if none exists)¶
netsh interface portproxy delete v4tov4 listenport=2222 listenaddress=0.0.0.0
Add the new portproxy rule¶
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=22 connectaddress=$wslIp
Open the port in Windows Firewall (only needs to be run once)¶
New-NetFirewallRule -DisplayName "WSL SSH" -Direction Inbound -LocalPort 2222 -Protocol TCP -Action Allow
Verify the rule¶
netsh interface portproxy show v4tov4