how can i ssh into wsl
To SSH into WSL (from Windows into the WSL instance):
sudo apt update
sudo apt install openssh-server
sudo service ssh start
Optional: sudo systemctl enable ssh
if using a systemd-enabled distro.
hostname -I
Alternatively, from PowerShell:
wsl hostname -I
sudo passwd $USER
Open PowerShell or Command Prompt:
ssh @
WSL IP changes on restart. To avoid that:
wsl.local
via mDNS (if supported):
ssh <user>@wsl.local
localhost
with port forwarding.In PowerShell:
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=127.0.0.1 connectport=22 connectaddress=
Then:
ssh @localhost -p 2222
Let me know if you’re trying to go the other way (SSH from WSL).
ssh into wsl from termux
To SSH into WSL from Termux on Android, here’s the plan:
In WSL:
sudo apt update
sudo apt install openssh-server
sudo service ssh start
sudo passwd $USER
In WSL:
hostname -I
Let’s say the IP is 172.22.99.44
.
WSL IP is typically on a virtual network and not visible to Android.
You can’t reach WSL directly from Android unless you:
On your Windows host (PowerShell as Admin):
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=22 connectaddress=
Also allow traffic through the firewall:
New-NetFirewallRule -DisplayName "WSL SSH" -Direction Inbound -LocalPort 2222 -Protocol TCP -Action Allow
Install OpenSSH in Termux (if not already):
pkg install openssh
Then connect:
ssh @ -p 2222
Find your Windows host IP (e.g., via ipconfig
or your router).
Note: WSL2 uses a NAT’d network. No direct access from LAN without portproxy tricks.
Want a persistent setup or script? I can help with that too.