ssh setup - ScottKirvan/WSL GitHub Wiki
Guide for configuring Password
- Edit
/etc/ssh/sshd_config
and change the listening port. For this demo I used port22
- Change
UsePrivilegeSeparation
to 'no
' (because the implementation of the Windows subsystem for Linux doesn't provide chroot) - Change
PasswordAuthentication
to 'yes
' - Add a firewall rule on the Windows side for SSH to your new listening port
sudo ssh-keygen -A
- Restart the ssh service:
sudo service ssh restart
(Ignore the message: "initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused") - Test ssh connection locally with verbose mode enabled (verbose mode optional):
ssh localhost -p "your-port-here" -v
- Test from another system. (All should be working)
Guide for configuring Password-less SSH
- Edit
/etc/ssh/sshd_config
and change the listening port. For this demo I used22
- Change the
UsePrivilegeSeparation
to 'no
' (because the implementation of the Windows subsystem for Linux doesn't provide chroot) - Add a firewall rule on the Windows side for ssh to your new listening port
sudo ssh-keygen -A
- Restart the ssh service:
sudo service ssh restart
(Ignore the message: "initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused")
Do this from client machine (system tunneling to Bash on Ubuntu on Windows)
cd ~/.ssh
ssh-keygen -t rsa
[Pause to complete step 1 on server side]scp -P "port-goes-here" ~/.ssh/id_rsa.pub username@server-ip-address:~/.ssh
Tip – If you have trouble copying the .pub file to your server, you might want to temporarily enable PasswordAuth
on the server (using the above instructions) to complete the scp transfer and then disable PasswordAuth promptly after. [Proceed to complete steps 2 – 5 on server side]
Do this from server machine (system running Bash on Ubuntu on Windows)
mkdir -p ~/.ssh/
[Pause to complete step 3 on client side]cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
rm .ssh/id_rsa.pub
To connect to your system running Bash on Ubuntu on Windows (server) from your client, run the following: ssh username@server-ip-address -p "your-port-here"
Configure SSH to auto-start SSH -- NOTE: THIS DOESN'T WORK - NEED PASSWORDLESS START
- Open Windows
Task Scheduler
- Click
Create Basic Task...
- set Name: "Start Bash SSH Server" & Description: "Start the WSL SSh Serer via a bash command"
- click
Next
- Set
Trigger
toWhen the computer starts
- click
Next
- set 'Action' to 'Start a program'
- click
Next
- under
Start a Program
, set Program/script:%windir%\System32\bash.exe
- set Add arguments(optional):
-c "sudo /etc/init.d/ssh start"
NOTE: This will require you enter your WSL password at startup
NOTE: I don't think this is going to work until I figure out how to runsudo service ssh --full-restart
without a password. I tried modifyingsudo visudo
to let me start sshd without passwords, but I can't get it to work in wsl.
fix: Win10 has OpenSSH available as part of the install -- see here: https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse