I have a question about the WSL version of Ubuntu. Is there an easy way to have bash start automatically when Windows starts and pass a command to it to start the SSH server? So that the SSH server runs all the time when Windows runs.

  • askubuntu.com/questions/1165969/… Related post. Also works for WSL 2 and windows 10. (for me at least) It's the same approach with the wsl.exe in the startup folder of windows.
    – Julian
    Oct 22, 2022 at 11:15

1 Answer 1


This also works on WSL 2.

Solution 1: use VBE script

Click on Start and search for shell:startup. also you can go manually to:

C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

now create a new file sshserver.vbe and add this text and save:

Set ws = CreateObject("Wscript.Shell") 
ws.run "wsl -d Ubuntu -u root service ssh start", vbhide

Solution 2: Task Scheduler

Click on Start and search for Task Scheduler.

  1. On Task Scheduler click on Action and select Create Basic Task

    enter image description here

  2. On Create Basic Task Fill out Name and Description "Auto Start SSH server"

    create Basic Task

  3. On Trigger select: When the computer starts.


  4. On Action select Start a program


  5. On Start a Program type path: C:\Windows\System32\wsl.exe, next on add Add arguments (optional): -d Ubuntu -u root service ssh start.

    Start a Program

You should have something like this on the last step.


  • When I try this command I get: "/bin/bash: -d: invalid option". When I remove -d Ubuntu but keep -u root there is a similar error. With "wsl service ssh start" it runs as a non-root user and fails. "wsl sudo service ssh start" asks for a password so it cannot be autorun at startup. Perhaps after editing visudo/sudoers it could work...
    – PF92
    Oct 11, 2019 at 8:52
  • 1
    use wsl not bash if you look close all my calls was made from windows not inside Linux. correct one: C:\Windows\System32\wsl.exe -d Ubuntu -u root service ssh start Oct 11, 2019 at 10:52
  • 1
    i forgot to mention this it's for wsl 2 Oct 11, 2019 at 10:54
  • another solutin to use bash it's to add in your /etc/sudoers this : << username >> ALL=(ALL:ALL) NOPASSWD: ALL , replace << username >> with your username then call: C:\Windows\System32\bash.exe -c "sudo service ssh start" Oct 11, 2019 at 11:00
  • I thought WSL2 was still in beta? Oct 11, 2019 at 15:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .