4

I just setup a small lab with an Ubuntu 17.10.1 VM on Hyper-V on a Win 10 host, and was trying to SSH from this VM into the WSL (Windows Subsystem for Linux) Ubuntu Instance in Win 10. I am constantly getting a connection timeout error.

To give you more a quick summary:

  1. I am able to SSH into the WSL Ubuntu Instance directly from my Win 10 host (using the new Open SSH Beta CLient for Win 10).
  2. I am able to SSH Into the Ubuntu 17.10.1 VM on Hyper-V from my Win 10 Host.
  3. I am able to SSH into the Ubuntu 17.10.1 VM on Hyper-V from the WSL Ubuntu Instance on Win 10.
  4. I am unable to SSH from the Ubuntu 17.10.1 VM on Hyper-V to the WSL Ubuntu Instance on Win 10.
  5. I already changed the SSH port in the WSL Ubuntu instance from 22 to 2222 in the sshd_config file, and set:

    UserPrivilegeSeparation No  
    PasswordAutherntication Yes  
    UsePAM to No  
    

    Next, I restarted the SSH Server.

The firewall on Win 10 is configured for Inbound rule to allow 2222 on TCP. No IPTables or any other Firewall on the WSL Ubuntu Instance

Please help diagnose the issue.

Update: Had also tried with -vvvv option. Here is the output:

Debug Output

  • You stated I am unable to SSH from the Ubuntu 17.10.1 VM on Hyper-V to the WSL Ubuntu Instance on Win 10 (4). Ok. Are you able to SSH to the WSL Ubuntu Instance on Win 10 from another point? I mean is there set any sshd equivalent on Win 10? If yes look again at the firewall rules. Maybe when you "SSH into the WSL" (1) you are using some internal path/special rule... Check for additional firewall rules on Hyper-V. – Hastur Mar 29 at 8:10
1
+100

I was finally able to figure out on how to resolve the issue myself after a stepwise logical analysis.

It was surprising to see that there is so limited Information out there on such a seemingly straightforward matter. MS documentation and all major WSL blogs have no Info.

So the key points to the solution based on my work here are as given below:

  • WSL runs on top of the underlying Windows 10 host as a process. This also means that they share the same IP address and hostname

  • For enabling SSH connectivity to/from WSL and Win 10, we need to have OpenSSH Server and OpenSSh Client installed on each one. For Windows 10, native OpenSSH Server is being assumed to be used here

  • Having OpenSSH Server running on both Win 10 host and WSL at the same time will conflict with each other, with the OpenSSH Server on Win 10 host getting precedence over the OpenSSH Server on WSL (and I could not find any direct way anywhere to keep both OpenSSH Servers running and switch priority/precedence exclusively). Interesting to note here that earlier when there was no native OpenSSh Server support before Win 10 (1809), we would typically use a Win32 ported version of OpenSSH Server, where this limitation around conflict would not occur since OpenSSH server did not run as a windows service then and had to be started explicitly.

  • Everytime you try to connect to the WSL using SSH from anywhere, you will end up having the SSH connection instead made to the OpenSSH Server Windows Service on the underlying Win 10 host. This means that NO SSH calls will be going to the OpenSSH Server running within WSL.

  • Solution here is to stop the OpenSSH Server Windows Service on the underlying Win 10 host. You need not touch the OpenSSh Authetication Agent Windows Service though. Please see the screenshot below, which is after I stopped the OpenSSH Server Windows Service on my Win 10 host.

OpenSSH Server and Authentication Agent Windows Services in Windows 10

  • Once you stop the OpenSSh Server Windows Service on the underlying Win 10 host, you will then be able to seamlessly connect to WSL normally through SSH from within CMD/PowerShell consoles in the underlying Win 10 host, and from any other Linux VM running on Hyper-V/VBox on same host, and from any other Win 10 VM running on Hyper-V/VBox on same host etc.

  • In case you have been trying different approaches for some time, better to clear all entries from your "known_hosts" file in your Win 10 host located @ "C:\Users\.ssh" folder. Otherwise you will likely get the error as shown in the screenshot below

Error: Host Key Verification Failed

0

one solution to this is to go to settings-> network ; then set adapter 1 to bridged, restart the vm. Then run ifconfig in the vm to get the new ip address

As far as I understand it, this solution sets the ip address within your network allowing you to access it via ip address.

  • 4
    If your method works then explain it with details, it'll help others. – Biswapriyo Mar 26 at 19:26
  • Sorry @brice but the solution you present doesn't work in this scenario. I resolved this myself after quite a bit of experimentation due to lack of sufficient documentation. – The Bahree Mar 31 at 5:55
  • I misread the question I was looking to ssh into the virtual machine from the WSL not the other way around. – Brice Apr 1 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.