127

I have Windows 10 Anniversary Edition with "Bash on Ubuntu on Windows" installed and working. I'd like to be able to SSH into this Ubuntu instance, but although I have openssh-server installed and configured (and listening on port 2200), when I try to ssh to "localhost:2200", it tells me "Server unexpectedly closed network connection".

Has anyone been able to successfully accomplish this?

enter image description here

2
  • Using Process Hacker and looking at the 'Network' tab, it shows sshd (running on Ubuntu on Windows 10) is listening on the 2200 local port.
    – Mick
    Commented Aug 9, 2016 at 15:08
  • and if you try to connect to the ip address of the system? Ubuntu often maps loopback addresses differently than windows does, and uses additional values in 127.0.0.0/8 (often 127.0.1.1) Commented Aug 9, 2016 at 15:29

5 Answers 5

145

I got it to work; here's how.

Uninstalled ssh-server, reinstalled it and made sure it's started with

sudo service ssh --full-restart

Make sure you turned off root access and added another user in the config file.

I was able to connect to the subsystem on 127.0.0.1:22 as expected.  I hope this will help you.

Here's a screenshot.

  1. sudo apt-get purge openssh-server
  2. sudo apt-get install openssh-server
  3. sudo nano /etc/ssh/sshd_config and disallow root login by setting PermitRootLogin no
  4. Then add a line beneath it that says:

    AllowUsers yourusername

    and make sure PasswordAuthentication is set to yes if you want to login using a password.

  5. Disable privilege separation by adding/modifying : UsePrivilegeSeparation no

  6. sudo service ssh --full-restart

  7. Connect to your Linux subsystem from Windows using a ssh client like PuTTY.

26
  • 3
    i didnt have to do that - strange.. but remember this is still in beta stage so results may vary Commented Aug 17, 2016 at 21:26
  • 8
    Additionally I had to: Stop/Disable Windows 10 SSH Server Broker Services from the services control panel and set: PubkeyAuthentication no in the sshdconfig
    – math0ne
    Commented Sep 16, 2016 at 3:49
  • 7
    I also needed to add a firewall rule. There was an existing rule, but that was only for the Windows SSH Server Proxy, and when I stopped that service, the firewall blocked traffic on port 22. Commented Sep 29, 2016 at 8:54
  • 4
    I also had to change ports (Port 2222 in /etc/ssh/sshd_config file), if not the ssh server of windows picked up the connection on port 22.
    – arod
    Commented Jan 13, 2017 at 2:12
  • 2
    @ArtemRussakovskii they stop the whole Linux subsystem whenever you close the bash window...
    – Saw
    Commented Jul 20, 2017 at 22:16
39

The above answers came close, but I still had a Connection closed by 127.0.0.1 issue.

So starting over from scratch and supplying the --purge option when removing the sshd package (as I demonstrate below), solved my variation of this issue:

user$ sudo apt-get remove --purge openssh-server # First remove sshd with --purge option.
user$ sudo apt-get install openssh-server
user$ sudo vi /etc/ssh/sshd_config # **See note below.
user$ sudo service ssh --full-restart

# ** Change Port from 22 to 2222. (Just in case MS-Windows is using port 22).
#    Alternatively, you can disable MS-Windows' native SSH service if you 
#    wish to use port 22.
7
  • 2
    Why the downvote? These instructions alone didn't work in my case, as mentioned, and the additional step above worked. I don't get it.
    – NYCeyes
    Commented May 16, 2017 at 4:54
  • 1
    I was having a very different error "No supported authentication methods available (server sent: publickey)" and these steps fixed it.
    – Mike Viens
    Commented Sep 2, 2017 at 11:52
  • 2
    For some reason, Windows just didn't appreciate that I was running on Port 2222. It didn't ever show any other processes using it, and there was no evidence of port conflict, but as soon as I changed ports, it began to work. Commented Jan 11, 2018 at 2:16
  • 1
    Port 2222 doens't work for me either, no other service running, but 22 works, which is a problem since I want to have multiple SSH connections.
    – mFeinstein
    Commented Aug 27, 2019 at 22:52
  • 2
    Just a simple remove then install worked for me. Commented Mar 20, 2020 at 11:15
27

Since windows implementation doesn't provide chroot you need to modify the /etc/ssh/sshd_config

UsePrivilegeSeparation no

Also you will need to create a user using useradd command or so.

4
  • 4
    This step was essential in getting it to work.
    – Mick
    Commented Aug 17, 2016 at 20:27
  • 1
    I was curious, so I found this at freebsd.org/cgi/man.cgi?sshd_config(5): UsePrivilegeSeparation:
    – krs013
    Commented Sep 1, 2016 at 7:46
  • Specifies whether sshd(8) separates privileges by creating an unprivileged child process to deal with incoming network traffic. After successful authentication, another process will be created that has the privilege of the authenticated user. The goal of privilege separation is to prevent privilege escalation by containing any corruption within the unprivileged processes. The argument must be "yes", "no"', or "sandbox". If UsePrivilegeSeparation is set to "sandbox" then the pre-authentication unprivileged process is subject to additional restrictions. The default is "sandbox".
    – krs013
    Commented Sep 1, 2016 at 7:46
  • 7
    WSL implemented chroot in September 2016 (after this answer). Commented Apr 28, 2017 at 8:21
5

I did everything as Master Azazel suggested and had the problem. When I connected to port 22 I was asked for a password, but the password I set in the Linux subsystem didn't work.

Solution #1:
change the SSH port in /etc/ssh/sshd_config and restart the SSH server in the subsystem

Solution #2:
disable/stop the "SSH Server Broker Services" in services control panel of Windows and restart the SSH server in the subsystem.

2
  • 1
    This only applies if you have something running on windows on port 22. Commented Dec 4, 2016 at 10:14
  • 3
    Ofcz, as you see on my default installation of win10 there was a service running on 22...
    – scotty86
    Commented Dec 5, 2016 at 11:47
2

The reason why you cannot ssh to it is shown in the logging from the server:

chroot("/var/run/sshd"): Function not implemented [preauth]

The Linux subsystem doesn't seem to have chroot implemented and the ssh server needs it so the connection is not allowed.

1
  • 4
    Which is correct.. but the other answers explain how to work around the chroot requirement. Commented Dec 12, 2016 at 20:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .