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”.

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
…

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
Changing MTU fixed the problem for me: https://github.com/microsoft/WSL/issues/4698#issuecomment-628682785
This (in PowerShell) appears to work around this issue for me:
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 1300orsudo ip link set dev eth0 mtu 1300Possible 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-permanentlyThis 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.
No active firewall / vpn
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
But if I revert to wsl1
wsl.exe --set-version Ubuntu 1It works ! 👍
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
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
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:
$ 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
rsyncand SSH from a WSL2 based Ubuntu 20.04.I can confirm this works for me:
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/netplanor in/etc/network/interfacesto 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 19041No 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.exeandssh.exefrom a Windowscmd.exeprompt does not exhibit the hangs?