Microsoft partnered with Canonical to create Bash on Ubuntu on Windows, running through a technology called the Windows Subsystem for Linux. Below are instructions on how to set up the ssh server to run automatically at boot.
- Uninstall and reinstall the ssh server using the following commands:
sudo apt remove openssh-server
sudo apt install openssh-server
- Edit the
/etc/ssh/sshd_config
file by running the commandsudo vi /etc/ssh/sshd_config
and do the following- Change
Port
to 2222 (or any other port above 1000) - Change
UsePrivilegeSeparation
to no - Change
PasswordAuthentication
to yes. This can be changed back to no if ssh keys are setup.
- Change
- Restart the ssh server:
sudo service ssh --full-restart
- With this setup, the ssh server must be turned on every time you run Bash on Ubuntu on Windows, as by default it is off. Use this command to turn it on:
sudo service ssh start
- Add in the end of .bashrc
# Run ssh on logging, only if not running yet if [ ! "$(ps -elf | grep -v grep | grep /usr/sbin/sshd)" ]; then sudo /usr/sbin/sshd; fi
- Finally, you will need to configure the ssh server to start without requiring password. Run the command
sudo visudo
and add this line to the end of the file: -%sudo ALL=NOPASSWD: /usr/sbin/sshd
Based the fact that I get errors or warnings, the following things should be changed:
# Run ssh on logging, only if not running yet if [ ! "$(ps -elf | grep -v grep | grep /usr/sbin/sshd)" ]; then sudo service ssh start; fi
add this line to the end of the file:"
%sudo ALL=NOPASSWD: /usr/sbin/service ssh *