Skip to content

How to automatically start ssh server on boot on Windows Subsystem for Linux

Notifications You must be signed in to change notification settings

tsc2017/WSL_SSH

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 

Repository files navigation

Forked from the gist How to automatically start ssh server on boot on Windows Subsystem for Linux

How to automatically start ssh server on boot on Windows Subsystem for Linux


This works with Ubuntu 20.04LTS. I make no promises about other distributions, but direct anyone else to an older Gist which apparently works for 16.04LTS.

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.

  1. Uninstall and reinstall the ssh server using the following commands:
    1. sudo apt remove openssh-server
    2. sudo apt install openssh-server
  2. 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:
    1. sudo service ssh start
  3. Follow the next steps which will create scripts that start the ssh server automatically:
    1. Create a sshd.bat file and edit it with the following commands:

      • Add the following code: C:\Windows\System32\bash.exe -c "sudo /etc/init.d/ssh start"
      • Save the file and move it to a more accessible location, e.g. mv sshd.bat /mnt/c/Users/YourUserName/Documents. Make sure to match your username! Take note of this location for the next step as in Windows language this corresponds to C:\Users\YourUserName\Documents
    2. Create a sshd.vbs file in the same directory and edit it with the following commands:

      • Add the following code, making sure to put in your actual user name:
      Set WinScriptHost = CreateObject("WScript.Shell")
      WinScriptHost.Run Chr(34) & "sshd.bat" & Chr(34), 0
      Set WinScriptHost = Nothing
      
      • Create a shortcut for this file and move it to a more accessible location, e.g. mv sshd.vbs /mnt/c/Users/YourUserName/Documents.
      • Open start menu, type run (or hit ⊞ Win+R ). Then type shell:startup. Copy the shortcut to the Startup folder
    3. 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: /etc/init.d/ssh
  4. If configured properly, the ssh server should now automatically start in the background when Windows starts.
  5. (optional) To use password authentication, run sudo nano /etc/ssh/sshd_config, set passwordAuthentication to yes and run sudo service ssh restart.
  6. (optional) In order to view GPU status using watch and nvidia-smi.exe in Windows, create a new session in Xshell, whose name is "WSL" and IP is 127.0.0.1. Set watch "/mnt/c/Windows/System32/nvidia-smi.exe" as a startup script for this session.

Note that the files created in My Documents can be synchronized by OneDrive. Note also that Xshell can be added to startup.

My thanks go to dentechy for his original GitHubGist on this subject. I found that the instructions he provides do not work if you've upgraded your Windows Subsystem Linux Ubuntu to 18.04LTS since the UsePrivilegeSeparation option has been depreciated on the ssh server for 18.04LTS. The above is my workaround.

About

How to automatically start ssh server on boot on Windows Subsystem for Linux

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •