WSL: WSL2 SSH can't connect to any public SSH server

Environment

Windows build number: 

Microsoft Windows [Version 10.0.19041.450]
Your Distribution version: Release:        20.04
Whether the issue is on WSL 2 and/or WSL 1: Linux version 4.19.104-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Feb 19 06:37:35 UTC 2020

Steps to reproduce

In the console try to connect to any public SSH service. For instance:

ssh -vvv new@sdf-eu.org
OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f  31 Mar 2020
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 "sdf-eu.org" port 22
debug2: ssh_connect_direct
debug1: Connecting to sdf-eu.org [178.63.35.195] port 22.
debug1: connect to address 178.63.35.195 port 22: Connection timed out
ssh: connect to host sdf-eu.org port 22: Connection timed out

Timed out is observed

Expected behavior

Successful connection.

Actual behavior

Timeout (no connection).

Running the same command in cmd makes successfull connection:

ssh -vvv new@sdf-eu.org OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5 debug3: Failed to open file:C:/Users/mresetar/.ssh/config error:2 debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2 debug2: resolving “sdf-eu.org” port 22 debug2: ssh_connect_direct: needpriv 0 debug1: Connecting to sdf-eu.org [178.63.35.195] port 22. debug1: Connection established. debug1: identity file C:\Users\mresetar/.ssh/id_rsa type 0 …

I don’t observe any other network issues in the WSL2 Bash. Curl, apt-get, git clone etc… they all work fine. Only SSH is problematic. My computer is recent install.

I’ve just tried ssh from docker (WSL2) and from container it works:

miro@mresetar:~$ docker run -it --rm kroniak/ssh-client bash bash-5.0# ssh -vvv new@sdf-eu.org OpenSSH_8.1p1, OpenSSL 1.1.1d 10 Sep 2019 debug1: Reading configuration data /etc/ssh/ssh_config debug2: resolving “sdf-eu.org” port 22 debug2: ssh_connect_direct debug1: Connecting to sdf-eu.org [178.63.35.195] port 22. debug1: Connection established. debug1: identity file /root/.ssh/id_rsa type -1

It looks to me like ssh client is broken on WSL2.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 9
  • Comments: 40

Most upvoted comments

Check if you have SEP (Symantec Endpoint Protection) firewall enabled. Disable it and try again.

If you connect successfully, it is the same issue I’m facing and that I was not able to resolve.

I’ve tried to re-install the distribution. If I try ssh in the WSL 1 version of Ubuntu-20.04 it works. As soon I convert the distro to the version 2 with wsl --set-version Ubuntu-20.04 2, ssh client stops to work.

This is really annoying.

Current list:

C:\Users\mresetar>wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

Same issue on WSL2, must be due to the latest windows update.

ssh -vvv asdf
OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/karl/.ssh/config
debug1: /home/karl/.ssh/config line 1: Applying options for *
debug1: /home/karl/.ssh/config line 7: Applying options for asdf
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 "asdf.com.py" port 22
debug2: ssh_connect_direct
debug1: Connecting to asdf.com.py [165.227.191.148] port 22.
debug1: connect to address 165.227.191.148 port 22: Connection timed out
ssh: connect to host asdf.com.py port 22: Connection timed out

That’s good to know. I have another scenario that works from WSL2

~$ ssh.exe -vvv new@sdf-eu.org

It is just Linux ssh which is stuck connecting. I guess it could be Win10 adapter / firewall that get’s in the way. But that is just guess.

@mehdighemati I’ve been struggling for the last hour or two trying to push a fresh repo into my github. SSH just won’t work, but when I use a VPN, it does push but stops after Writing Objects and Total then displays a ssh_dispatch_run_fatal: Connection to {ip_address} port 22: Connection timed out error.

This might be a bigger issue if we both are having this problem at the same time. I also run Ubuntu 20.04 LTS on WSL2.

I tried disabling IPV6 as suggested by @Sublime1, but it did not work for me. I am using a VPN and had to disable ipv6 in both the VPN and the wifi network.

@mresetar could you please give more details on how to follow your solution? I don’t know how to access those screens you printed.

It seems that people are still facing the same issues although this has been marked as closed.

Steps mentioned here worked for me.

@tolaini you are 100% correct. I’m using SEP and had firewall turned on. I’ve requested admin rights to turn off the firewall. After turning it off, temporarily, I can connect successfully. We need a solution for this. Microsoft and Symantec should figure this out together.

i started facing it today (yesterday was working good, i dont change anything, just shutdown my computer), my shh suddetly stops to work to connect a public server that i can connect from outside WSL.

if i open de windows CMD and try connect to public by shh it works, but inside WSL dont work.

Hi, I just spoke with my SEP admin and I can share few details. It looks there is no magic involved there. Symantec doesn’t by magic recognize WSL as Hyper-V and treat it differently. It is just a Group policy in our case that was named Hyper-V. So for people who use Hyper-V admins created a special Group policy where they allow some ports. What is important to note that ports allowed have Incoming TCP port opened. I would say that to Win10 it looks like incoming traffic when WSL2 tries to open SSH connection. So screenshots of the group policy with the special (No 1) rule: image

Details of the rule: image

Notice that there are few other ports besides 22. I wasn’t only one requesting some ports to be opened 😃

Hi sir, please guide it details?

Similarly, I can ssh from the cmd window and also ssh from a vitual box VM. I just can’t ssh from WSL2. I have added a special rule for incoming port 22 on my windows firewall and even tried just turning off the windows firewall altogether. No luck. I’m win10 and using IP address so no DNS issues. Still searching for the answer here and it is certainly unique to WSL2.

My SSH it was blocked by Norton 360 in a mysterious way. But in the link below I found two temporary solutions that solves the problem to me. https://askubuntu.com/questions/1229456/ssh-fails-with-connection-timed-out-in-vpn-and-hangs-here-expecting-ssh2-msg

@tolaini you are 100% correct. I’m using SEP and had firewall turned on. I’ve requested admin rights to turn off the firewall. After turning it off, temporarily, I can connect successfully. We need a solution for this. Microsoft and Symantec should figure this out together.

exactly same situation It worked for me but one day it stopped. I guess something is wrong with network configuration. I tried to reinstall windows linux subsystem but it is ended the same. Maybe there is a way to re-init whole network settings in wsl ? i tried to install debian but it has same trouble with ssh as ubuntu. Imust some global wsl config