How to SSH into WSL

35

6

Long-time reader, first-time question-asker.

I followed the instructions in this answer:

How can I SSH into “Bash on Ubuntu on Windows 10”?

I'm attempting to SSH from PuTTY in Windows on the same machine. Using Port 22, which matches my config file. Tried both 127.0.0.1 and 127.0.1.1. However, I'm still getting "access denied":

enter image description here

Ultimately I'm hoping to set up a Visual Studio remote build, but I've been thus far unable to get in remotely at all. What next steps should I take?

Process Hacker shows this for port 22 (not sure what this means):

enter image description here

Here are the contents of /etc/ssh/sshd_config:

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation no

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin no
AllowUsers basel
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile     %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

Basel Alghanem

Posted 2016-09-12T14:20:28.147

Reputation: 353

An "Access Denied" means you are providing the incorrect password to the account base1 – Ramhound – 2016-09-12T14:26:50.203

1I'm definitely not providing the incorrect password. I've changed it and retried a few times just to make sure. – Basel Alghanem – 2016-09-12T14:32:07.027

Did you try looking around?

– Matt Clark – 2016-09-12T14:37:56.577

1I absolutely did try looking around, for a couple hours this morning. Unfortunately I'm generally unknowledgeable in this area. I tried commenting out the line as suggested in an answer, and that didn't help. Do you think trying key-based auth might work? – Basel Alghanem – 2016-09-12T15:09:50.177

Update: When I ssh into 127.0.0.1 or 127.0.1.1, I am able to log into Windows using my Windows credentials. I'm thinking maybe I need to use a different port because 22 is being used by Windows? – Basel Alghanem – 2016-09-12T16:27:02.127

If you used key-based authentication, and it works, then its an authentication problem. If you change the port, and it works, then you still have authentication problem – Ramhound – 2016-09-12T16:36:33.360

1Switched to port 2200 (line 5 in sshd_config) and was able to successfully log into WSL. I guess Windows was using port 22 so Linux couldn't? Additionally, sshd showed up in Process Hacker as listening to port 2200, where it didn't show up at all before. Do I submit this as an answer to my question? – Basel Alghanem – 2016-09-12T16:40:57.530

Answers

27

Change the 22 port to a other one,such as 2222,in the file /etc/ssh/sshd_config,then restart the ssh service by the commond sudo service ssh --full-restart,you will successfully login.But I don't know the reason.

I also try use it as a remote gdb server for visual studio by VisualGDB,it not works well. VisualGDB will support it in the next version as the offical website shows.The link is https://sysprogs.com/w/forums/topic/visualgdb-with-windows-10-anniversary-update-linux-support/#post-9274

nul lun

Posted 2016-09-12T14:20:28.147

Reputation: 388

Now,the VisualGDB support it,more details to http://visualgdb.com/tutorials/linux/win10/

– nul lun – 2016-10-26T03:25:37.163

But it sames that it doesn't use ssh.Maybe just use windows commond to call the gdb in wsl. – nul lun – 2016-10-26T03:41:51.390

4This is because Windows might run SSH Server Broker on port 22. Unless you know for sure that you need it, it can be safely disabled. It is used for some procedures during development. – UnclickableCharacter – 2017-03-06T20:44:17.893

3Don't forget to open up the port in the Windows Firewall. – dthor – 2017-11-07T22:18:45.860

3Probably, you'll also need to change the authentication. By default it requires ssh keys to the client. If you want the classic user/password login, set this configuration in /etc/ssh/sshd_config: PubkeyAuthentication no PasswordAuthentication yes – Tonatio – 2018-01-29T11:55:33.673

1I had to enable firewall rule like @dthor mentioned and enable password auth like Tonatio mentioned then it worked. – sdkks – 2018-04-14T08:35:30.963

I can connect to 22 but not to 2222, even allowed it on the Windows Firewall, any ideas why? – mFeinstein – 2019-08-27T22:45:08.507

12

Port 22 does not work because Windows comes with a built in SSH server.

Windows 10 comes with an SSH server, and it will either need to be disabled or the port that will be used for SSH on WSL will need to be changed. I chose to do the latter and use port 2200 for WSL SSH.

Source: https://virtualizationreview.com/articles/2017/02/08/graphical-programs-on-windows-subsystem-on-linux.aspx

ayao1337

Posted 2016-09-12T14:20:28.147

Reputation: 478

1This is actually the only correct answer to this question, even the accepted answer, hints at this being the reason the port had to be changed. I am going to award this answer a bounty in 24 hours. – Ramhound – 2019-11-13T04:00:21.997

2

When you login, use your Windows Microsoft Account password, not your WSL Linux user password. You will be logged into your Windows home directory running cmd.exe. Enter command /windows/system32/bash.exe ~ --login to log into your WSL home directory and execute your .profile.

rhmccullough

Posted 2016-09-12T14:20:28.147

Reputation: 381

1

WSL: Also look out for 'UsePrivilegeSeparation no' Otherwise, running the server on the console (/usr/sbin/sshd -Dddde) will fail with PrivilegeSeparation not implemented ...

ga_t

Posted 2016-09-12T14:20:28.147

Reputation: 11

1UsePrivilegeSeparation is deprecated – mFeinstein – 2019-08-27T22:44:18.590

0

What I did was sudo ssh-keygen instead of ssh-keygen ran into some earlier problems with files not writing correctly and this fixed it for me

META

Posted 2016-09-12T14:20:28.147

Reputation: 1