WSL: SSH connections hanging from WSL2

Current Version 10.0.19025.1

I have this weird issue where I can no longer use SSH connections to remote servers from WSL2. I remember that it was working ok in early builds but I am not sure at which point it started to fail.

Any idea on how to resolve this would be appreciated.

What happens

When connected to a remote server, SSH connection hangs after a very short time. I am sometimes able to type a few letters but then it hangs and have to close WSL. It does this with every SSH connections to every server.

For instance, on the following screenshot, you can see that I was able to type a few numbers but the connection froze at the last “1”.

image

Probably related, SSH git cloning is not working either. It starts receiving objects but stops shortly after. I have to CTRL-C to stop. Here’s an example hanging at 46%.

> GIT_SSH_COMMAND="ssh -vvv" git clone --verbose git@github.com:microsoft/dotnet.git

… image

In WSL1, everything works smoothly and have no issues. It’s only in WSL2 that this happens.

Note that git cloning through HTTPS works fine as well.

Just let me know if there is additional trace I can run to help since I know this is probably going to be hard to repro.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 32
  • Comments: 69

Most upvoted comments

This (in PowerShell) appears to work around this issue for me:

New-NetFirewallRule -DisplayName "WSL" -Direction Outbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

Inspired by this comment: https://github.com/microsoft/WSL/issues/4585#issuecomment-610061194.

I have “solved” this issue: Removed WSL + all Hyper-V stuff and moved over to VirtualBox with a dedicated Linux VM.

I can confirm that decreasing MTU on eth0 solved the problem for me: sudo ifconfig eth0 mtu 1300 or sudo ip link set dev eth0 mtu 1300

Possible problem is IP packet fragmentation as explained here http://www.snailbook.com/faq/mtu-mismatch.auto.html . In my case it’s caused probably by VPN.

Unfortunately change is not permanent (and changing in windows did not helped): for now I have this in .bashrc:

#update MTU on eth0 MTU_SIZE=1347 if [[ $(ifconfig eth0 | sed -nr ‘s/.*mtu ([0-9]+)/\1/p’) -ne “$MTU_SIZE” ]]; then sudo ifconfig eth0 mtu $MTU_SIZE; fi

Actual MTU size would be probably individual - if caused by local VPN then you can check in windows - run command: netsh interface ipv4 show subinterfaces - check interfaces - see which one is used by VPN and check MTU size. Or you can experiment as described here: https://askubuntu.com/questions/1127497/how-can-i-change-mtu-size-permanently

This was stopping us moving to WSL2 as we are using Azure AlwaysOn VPN which failed every time we ran an ssh session and did an ls but worked when we used OpenVPN. I struggled searching for the answer for weeks and finally raised with Mircosoft Azure support who advised to change the MTU to 1400 or 1300 using the command:

“sudo ip link set dev eth0 mtu 1400”

This worked for me - hope it helps.

The usual “are you running any third-party VPN or firewall software” question applies

No active firewall / vpn

Is it correct to say git.exe and ssh.exe from a Windows cmd.exe prompt does not exhibit the hangs?

Exactly, everything works fine from cmd/ps and from WSL1 as well

For people with HP laptops, our team was able to resolve most of their SSH hanging issues in WSL2 by disabling the “LiveQoS NDIS 6 Filter Driver” on all ethernet/wifi adapters.

It looks like there is some conflict between WSL2 and this driver.

It has been mentioned in #5787 by @dpiow as well here

Hope this helps.

No VPN or firewall & I’m on WSL2

git clone git@github.com:maxdobeck/gimme.git
Cloning into 'gimme'...
Received disconnect from 192.30.255.112 port 22:11: Bye Bye
Disconnected from 192.30.255.112 port 22
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
ssh -vvv -T git@github.com
OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/max/.ssh/config
debug1: /home/max/.ssh/config line 1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolving "github.com" port 22
debug2: ssh_connect_direct
debug1: Connecting to github.com [192.30.255.112] port 22.
debug1: Connection established.
debug1: identity file /home/max/.ssh/id_rsa type 0
debug1: identity file /home/max/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: Remote protocol version 2.0, remote software version babeld-fceaa46c
debug1: no match: babeld-fceaa46c
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to github.com:22 as 'git'
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c
debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,sk-ssh-ed25519@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256
debug2: host key algorithms: ssh-dss,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc
debug2: MACs ctos: hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib,zlib@openssh.com
debug2: compression stoc: none,zlib,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 1
Received disconnect from 192.30.255.112 port 22:11: Bye Bye
Disconnected from 192.30.255.112 port 22

But if I revert to wsl1 wsl.exe --set-version Ubuntu 1

wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Running         1

It works ! 👍

ssh -T git@github.com
Hi maxdobeck! You've successfully authenticated, but GitHub does not provide shell access.

I have the same issue. WSL1 in VM - connection to SSH server is ok. (VPN) WSL2 in VM - connection to SSH server is ok (VPN), but when I grep for example larger output from text file it hangs and shows broken pipe aftewards. W10 - 2004 Ubuntu-20.04

MPU of the eth0 adapter is the cause

In case anyone has in the same issue. I do not find the logic of the issue. I tried all options and none worked. My setup is:

* Windows 11

* WSL 2 Ubuntu 22.04

* VPN

As one solution I read that you have to match the MTU of your VPN adapter and WSL eht0 adpater. That did not work for me. Honestly I just started testing random MTU number until it worked with 700. You can try several values and maybe it helps you sudo ip link set dev eth0 mtu 700

This worked for me when hanging on git push in WSL2.

Attached the following logs. First with MTU at 1500 then with MTU at 1400 WslLogs-2024-09-19_15-24-18.zip WslLogs-2024-09-19_15-25-16.zip

Debian 11 (bullseye) in WSL2 shows the ssh hanging as well.

To diagnose if MTU is the culpit try these commands

# This works for me - prints 80 dashes
ssh username@172.29.1.10 printf -- '-%.0s' {1..80}
# This works aswell - prints 580 dashes
ssh username@172.29.1.10 printf -- '-%.0s' {1..580} 
# This fails for me - just hangs
ssh username@172.29.1.10 printf -- '-%.0s' {1..618}

So while we say that the MTU is an issue on WSL, it also exists on Git Bash for Windows (MINGW64) It did fail once, but not permanently. I saw it working with 80, 580, but fail on 718, and work on 750, so this seems better than WSL, but still inconsistent.

I was also running on WSL2, over a ZeroTier connection which has its own MTU issues, however, when I connected directly to the machine, I did not have the issues. I could just connect with no issues.

So there are most likely several layers of issues in this issue.

The only real workaround that worked for me is to use cmd -> ssh.exe. Far from optimal as it clearly states that network integration with WSL2 is not working as it should.

I hope Microsoft will ditch the windows kernel soon and switch to a linux kernel as all other (important) operating system have done. Even if I am not looking forward to a virus being fitted to attack a linux kernel.

It seems to be realted, however it’s even a bit stranger on my side… Everything works as expected for like 30 seconds, thereafter the connection freezes. However I experienced that establishing the SSH connection and just waiting a few minutes somehow fixes the problems sometimes. I could then eventually use the connection the whole day without any freezes.

This only happens to me in WSL2 and changing the MTU did not work for me yet.

I too have the same problem. I just upgraded to Windows 2004 and WSL 2 and cannot connect to hosts on the VPN network. I can however connect to hosts on AWS.

When I’m using Powershell to connect to the VPN hosts it works fine, problem is only under WSL 2.

Interestingly when I use docker (with the wsl2 backend enabled), to start a alpine container from within wsl2 and I try to ssh into one of the hosts from there it works just fine.

Same issue: SSH does not connect at all (while putty or ssh.exe in terminal does work). Windows 11 (version 10.0.22621) and WSL2 with Ubuntu 22.04. None of the suggested fixes worked.

Time for yet another bump:

wsl -v WSL version: 1.2.5.0 Kernel version: 5.15.90.1 WSLg version: 1.0.51 MSRDC version: 1.2.3770 Direct3D version: 1.608.2-61064218 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.22000.2057

$ uname -a Linux blahh 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/os-release PRETTY_NAME=“Ubuntu 22.04.2 LTS” NAME=“Ubuntu” VERSION_ID=“22.04” VERSION=“22.04.2 LTS (Jammy Jellyfish)”

SSH fails after random periods. Even with continual traffic, keepalives etc.

Time to time this occurs to me too. I had changed MTU to 1350 and that had fixed the issue. Now when it occurs I just restart my laptop unfortunately.

I have ‘solved’ this problem by simply using the power shell with ssh and scp … I really wonder why Microsoft is not able to FIX this problem!

In fact, MTU adjustment works. I had to set it to 1350. 1400 doesn’t work.

But the real problem is NAT in WSL2. This is the most unexpected and unwanted staff. That’s what I think should be removed. I rolled back my environment to WSL1.

I am getting this too using rsync and SSH from a WSL2 based Ubuntu 20.04.

I can confirm this works for me:

Changing MTU fixed the problem for me: #4698 (comment)

From that comment: sudo ifconfig eth0 mtu 1350

…But that needs to be run every time the VM reboots which is not ideal. I’m not certain what would be needed to set the MTU to that value on the VM permanently - I don’t have anything in /etc/netplan or in /etc/network/interfaces to edit (but I suppose technically that is a little out of scope for this issue).

I also have this problem in WSL2 - nothing of these worked for me:

OS: Windows 10 Pro 10.0.19041 N/A Build 19041

Just let me know if there is additional trace I can run to help since I know this is probably going to be hard to repro.

No easy guesses off the cuff, and nothing similar on the books I know of. The usual “are you running any third-party VPN or firewall software” question applies. Is it correct to say git.exe and ssh.exe from a Windows cmd.exe prompt does not exhibit the hangs?