Setup WSL for Remote SSH Access
1. Reinstalling SSH on WSL 2
sudo apt remove openssh-server
sudo apt install openssh-server
2. Configuring SSH on WSL 2
sudo nano /etc/ssh/sshd_config
Change #Port 22
to Port 22
to enable the default port.
Change #PasswordAuthentication yes
to PasswordAuthentication yes
to enable password authentication.
3. Configuring Port Forwarding on Windows
netsh interface portproxy delete v4tov4 listenport=2222 listenaddress=0.0.0.0 protocol=tcp
for /f %%i in ('wsl hostname -I') do set IP = %%i
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=2022 connectaddress=%IP%
4. Enabling Inbound Rule on Windows Firewall
New-NetFirewallRule - Name sshd - DisplayName ' OpenSSH Server (sshd) for WSL' - Enabled True - Direction Inbound - Protocol TCP - Action Allow - LocalPort 2222
5. Set up Port Forwarding on Router (For WAN)
Navigate to Port Forwarding settings in the router’s configuration page.
Forward traffic from port 2220
to port 2222
on the IP address of your Windows machine (e.g. 192.168.100.1
).
Verifying on a Local Area Network
ssh wsl2username@ 192.168.100.2. -p 2222
Verifying on a Wide Area Network
ssh wsl2username@ 172.16.254.3 -p 2220