You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SSH into WSL from a remote machine not working #5131
this is actually a network "behavior" on Windows side. Your issue is that the port 2222 (or any ports from WSL->Windows actually) are bound to 127.0.0.1 on Windows side instead of 0.0.0.0 or your Windows IP address.
A workaround would be to tunnel your port towards your IP address for example: netsh interface portproxy add v4tov4 listenaddress=localhost listenport=2222 connectaddress=<your IP address> connectport=2222
And, if you really want it "constant", then you can had this to your Powershell $PROFILE (or a script launched by a windows task):
# Get your IP$env:MainIP=(Test-Connection-ComputerName (hostname) -Count 1).IPV4Address.toString()
# Cleans the tunnels table
(netsh interface portproxy reset all)
(netsh interface portproxy add v4tov4 listenaddress=localhost listenport=2222 connectaddress=$env:MainIP connectport=2222)
Hope this helps.
WSL Corsair
Reacted by Hayden Barnes, Jonathan ten Hove and Xavier Rigau
so you are waiting a connection done on the main IP from your external computer and then it will tunnel to your localhost.
And if it still doesn't work, try mapping the connectaddress to your WSL IP
Reacted by Bart Plasmeijer, Jake Goritski, Aaron, Tim van den 🔚, Ankon Mukherjee, Hydrz D and John Gilbert
so you are waiting a connection done on the main IP from your external computer and then it will tunnel to your localhost.
And if it still doesn't work, try mapping the connectaddress to your WSL IP
After reading your message Nuno do Carmo (@nunix) , I agree to invert the listening, and YES, it works...
Was this issue solved ? I've been trying to do the same thing.
Say I have two machines, A and B.
A: Win 10 Laptop
B: Win 10 PC with WSL installed
Only Ubuntu18.04 is installed on WSL.
On B - I have configured firewall for inbound port 2222 for private and domain networks.
I have OpenSSH server running on Windows in B and also SSH server running on WSL in B.
I use rsa public keys to authenticate - A (CMD/Powershell) to B's OpenSSH Windows server and B (CMD/Powershell) to B's SSH Server on WSL.
I can SSH from B into its WSL, but I can't SSH from A to B's WSL directly.
# On B, Powershell
PS C:\Users\kogam> netstat -ao | select-string 2222
TCP 127.0.0.1:2222 HOME-3700X-2060:0 LISTENING 11556
# On B, Powershell
PS C:\Users\kogam> Get-Process -Id 11556
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
------ ----- ----- ------ -- -- -----------
11 1.19 4.73 1.39 11556 1 wslhost
# On B, WSL
kogam22@HOME-3700X-2060:~$ netstat -ao
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State Timer
tcp 0 0 0.0.0.0:2222 0.0.0.0:* LISTEN off (0.00/0/0)
tcp6 0 0 [::]:2222 [::]:* LISTEN off (0.00/0/0)
tcp6 0 0 ip6-localhost:43024 ip6-localhost:2222 ESTABLISHED off (0.00/0/0)
tcp6 0 0 ip6-localhost:2222 ip6-localhost:43024 ESTABLISHED keepalive (6540.41/0/0)
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] SEQPACKET LISTENING 15060 /run/WSL/1303_interop
unix 2 [ ACC ] SEQPACKET LISTENING 20734 /run/WSL/1822_interop
unix 3 [ ] STREAM CONNECTED 15814
unix 3 [ ] STREAM CONNECTED 15813
Activity
nunix commentedon Apr 24, 2020
hi Bart,
this is actually a network "behavior" on Windows side. Your issue is that the port 2222 (or any ports from WSL->Windows actually) are bound to 127.0.0.1 on Windows side instead of 0.0.0.0 or your Windows IP address.
A workaround would be to tunnel your port towards your IP address for example:
netsh interface portproxy add v4tov4 listenaddress=localhost listenport=2222 connectaddress=<your IP address> connectport=2222And, if you really want it "constant", then you can had this to your Powershell $PROFILE (or a script launched by a windows task):
Hope this helps.
WSL Corsair
bplasmeijer commentedon Apr 25, 2020
hi Nuno do Carmo (@nunix)
:

no access from the remote
no firewall enabled on machine
more tips Nuno do Carmo (@nunix) ?
nunix commentedon Apr 25, 2020
Ok my bad, I read it the "wrong way", let's try to invert the listening and connection
so you are waiting a connection done on the main IP from your external computer and then it will tunnel to your localhost.
And if it still doesn't work, try mapping the
connectaddressto your WSL IPbplasmeijer commentedon Apr 25, 2020
After reading your message Nuno do Carmo (@nunix) , I agree to invert the listening, and YES, it works...
Now the big question for Craig Loewen (@craigloewen-msft) and Hayden Barnes (@sirredbeard), I did go into the other route based on netstat info, and firewall settings. Do we want this "behavior" with the portproxy on WSL?
Windows Firewall dialog for a port rule:
1ycx commentedon Jul 16, 2020
Was this issue solved ? I've been trying to do the same thing.
Say I have two machines, A and B.
A: Win 10 Laptop
B: Win 10 PC with WSL installed
Only Ubuntu18.04 is installed on WSL.
On B - I have configured firewall for inbound port 2222 for private and domain networks.
I have OpenSSH server running on Windows in B and also SSH server running on WSL in B.
I use rsa public keys to authenticate - A (CMD/Powershell) to B's OpenSSH Windows server and B (CMD/Powershell) to B's SSH Server on WSL.
I can SSH from B into its WSL, but I can't SSH from A to B's WSL directly.
therealkenc commentedon Sep 1, 2020
/dupe #4150