Ubuntu – WSL Ubuntu, is there an easy way to have bash start automatically on Windows startup

windows-subsystem-for-linux

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.

Best Answer

  • (( update this 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 It's Task Scheduler

    Click on Start and search for Task Scheduler.

    On Task Scheduler click on Action and select Create Basic Task enter image description here

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

    create Basic Task

    On Trigger select: When the computer starts.

    Trigger

    On Action select Start a program

    Action

    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.

    finish