WSL icon indicating copy to clipboard operation
WSL copied to clipboard

ssh from Windows to WSL2 failed with error: 10061

Open astroboylrx opened this issue 5 years ago • 11 comments

Windows Build Number

Microsoft Windows [Version 10.0.21370.1]

WSL Version

  • [X] WSL 2
  • [ ] WSL 1

Kernel Version

5.10.16

Distro Version

Ubuntu 20.04

Other Software

No response

Repro Steps

Nothing special, I followed the official guide and installed OpenSSH using PowerShell.

On the WSL2 side, I also have OpenSSH installed:

openssh-server/focal-updates,focal-security,now 1:8.2p1-4ubuntu0.2 amd64 [installed]

and the server is running:

➜  ~ sudo service ssh status
 * sshd is running

and is listening to port 2222 with the following setup in /etc/ssh/sshd_config:

ListenAddress 127.0.0.1
Port 2222
PasswordAuthentication yes
PubkeyAuthentication yes

Expected Behavior

Given the setup I have, executing the command ssh myself@localhost -p2222 should connect me to WSL2 from Windows.

Actual Behavior

Since build 21354.1, I cannot ssh into WSL2 from Windows with ssh myself@localhost -p2222, which I have used w/o problem for quite some time.

Now it always gives error 10061

PS C:\Users\astro> ssh -vvv myself@localhost -p2222
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Reading configuration data C:\\Users\\myself/.ssh/config
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolving "localhost" port 2222
debug2: ssh_connect_direct
debug1: Connecting to localhost [::1] port 2222.
debug3: finish_connect - ERROR: async io completed with error: 10061, io:0000022654ACBB70
debug1: connect to address ::1 port 2222: Connection refused
debug1: Connecting to localhost [127.0.0.1] port 2222.
debug3: finish_connect - ERROR: async io completed with error: 10061, io:0000022654ACBB70
debug1: connect to address 127.0.0.1 port 2222: Connection refused
ssh: connect to host localhost port 2222: Connection refused

In build 21354, sometimes I was able to change the port number (e.g., 2225) and make this work. Though this workaround fails since build 21364. In rare cases, a reboot fixes this issue. But it feels like lottery and I haven't found the pattern.

Diagnostic Logs

If you have suggestions about extra logs that I may find and add here, please let me know. Thanks.

astroboylrx avatar Apr 29 '21 20:04 astroboylrx

Thanks for the report; I was able to reproduce here on 21364. As a work-around WSL2's eth0 address takes.

image

therealkenc avatar Apr 29 '21 20:04 therealkenc

Thanks for the report; I was able to reproduce here on 21364. As a work-around WSL2's eth0 address takes.

Thanks a lot for the prompt follow-up!

Interesting, I saw your WSL2 has an eth0 address starting with 192.168. I thought WSL2 is often assigned an address within 172.16.0.0/12. I only encountered 192.168 once after upgrading to build 21354 (at the first reboot). After that, the address changed back to 172.XX and never become192.168.XX again. I wonder what's behind this and under what circumstance will WSL2 get 192.168.XX?

astroboylrx avatar Apr 29 '21 21:04 astroboylrx

I wonder what's behind this and under what circumstance will WSL2 get 192.168.XX?

How WSL2 comes up with its eth0 IP address is a mystery to not just you. I had to reboot, and mine is now 172.*. Don't read anything into it (I don't).

image

Wsl.etl logs are here and the bat output is here.

therealkenc avatar Apr 29 '21 21:04 therealkenc

Any update on this? I've been working on my new windows machine for one or two weeks. Everything worked initially and I've been able to ssh into WSL2 via localhost smoothly. However, today I again ran into the same issue listed here all of a sudden. I tried to uninstall recently installed softwares but got no luck. It is really frustrating and not too much info about this ERROR: async io completed with error: 10061 is available online.


Build: Microsoft Windows [Version 10.0.22471.1000]

astroboylrx avatar Oct 26 '21 07:10 astroboylrx

I have the same issue on my new Windows 11 machine, the error occures both in WSL2 and in the Windows powershell.

Gornoka avatar Nov 06 '21 12:11 Gornoka

Any update? :(

jvrfaria avatar Nov 20 '21 04:11 jvrfaria

I think I finally found what happened behind it. As pointed out by this article,

Allegedly a botched Windows update resets the dynamic TCP port range in some cases. When this happens, Hyper-V ends up aggressively reserving it for its own Windows Container Host Networking Service (HNS).

The reserved ports for TCP was sparsely distributed from 49152 to 65536. However, some earlier Windows update made the reserved ports ranged from 1259 to 65536, and the exact ports change each reboot. That's why sometimes ssh-ing from Windows to WSL via port 2222 works and sometimes it fails with error 10061. The command netsh interface ipv4 show excludedportrange protocol=tcp will show all the ports that are reserved.

As a solution, one may follow the aforementioned article and manually restrict the port range allowed for reservation. Alternatively, one may follow this post to prevent Windows reserving certain ports they desire.

astroboylrx avatar Dec 07 '21 20:12 astroboylrx

Oh, this report is good to I found. Its have same:

@PS C:\Windows\system32> wsl --version
WSL-verziďż˝: 1.0.3.0 
Kernelverziďż˝: 5.15.79.1
WSLg-verziďż˝: 1.0.47
MSRDC verzi�ja: 1.2.3575
 Direct3D-verziďż˝: 1.606.4 
 DXCore verzi�ja: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp 
Windows verzi�ja: 10.0.1904
PS C:\Windows\system32> ssh -p 2022 [email protected]
gyx@W10-xx:~$ exit 
 logout
 Connection to 172.31.81.48 closed

debug3: finish_connect - ERROR: async io completed with error:

PS C:\Windows\system32> ssh -vvv -p 2022 [email protected]                                                            OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2 
debug3: Failed to open file:C:/Users/gyurmo/.ssh/config error:2 
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolve_canonicalize: hostname 192.168.0.12 is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.0.12 [192.168.0.12] port 2022.
 debug3: finish_connect - ERROR: async io completed with error: 10061, io:000001D271465780
 debug1: connect to address 192.168.0.12 port 2022: Connection refused 
ssh: connect to host 192.168.0.12 port 2022: Connection refused 
PS C:\Windows\system32> netsh interface portproxy show v4tov4                                                                                                                                                                                   Listen on ipv4:             Connect to ipv4:                                                                                                                                                                                                    Address         Port        Address         Port
--------------- ----------  --------------- ---------- 
192.168.0.12    2022        172.31.81.48    2022                                                                                                                               

gyurmogyuri avatar Jan 15 '23 11:01 gyurmogyuri

I'm sorry. I solved: netsh interface portproxy delete v4tov4 listenport=2022 listenaddress=192.168.0.12 netsh interface portproxy set v4tov4 listenport=2022 listenaddress=192.168.0.12 connectport=2022 connectaddress=127.0.0.1

Because I have: localhostforwarding=true

gyurmogyuri avatar Jan 15 '23 14:01 gyurmogyuri

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!

I have this same issue.

lk-1984 avatar Feb 14 '24 17:02 lk-1984