How can I SSH into "Bash on Ubuntu on Windows 10"?
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?
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.
sudo apt-get purge openssh-server
sudo apt-get install openssh-server
-
sudo nano /etc/ssh/sshd_config
and disallow root login by settingPermitRootLogin no
-
Then add a line beneath it that says:
AllowUsers yourusername
and make sure
PasswordAuthentication
is set toyes
if you want to login using a password. Disable privilege separation by adding/modifying :
UsePrivilegeSeparation no
sudo service ssh --full-restart
Connect to your Linux subsystem from Windows using a ssh client like PuTTY.
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.
I hope this helps. \(◠﹏◠)/
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.
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.
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.