Skip to content

Instantly share code, notes, and snippets.

@rajibdpi
Last active September 3, 2024 18:46
Show Gist options
  • Save rajibdpi/b25c0d098867453794976ba33104fe11 to your computer and use it in GitHub Desktop.
Save rajibdpi/b25c0d098867453794976ba33104fe11 to your computer and use it in GitHub Desktop.
How to make automatically run the WSL services for ssh, apache2, mysql at Startup

#How to make automatically run the WSL services for ssh, apache2, mysql at Startup:

Step: 1
Add below lines in sudo nano /etc/sudoers WSL to prevent asking password:

%sudo   ALL=(ALL) NOPASSWD: /usr/sbin/service ssh start
%sudo   ALL=(ALL) NOPASSWD: /usr/sbin/service apache2 start
%sudo   ALL=(ALL) NOPASSWD: /usr/sbin/service mysql start

Step: 2
Create wslservices.bat file in Windows startup directory:

Press Win + R  and type shell:startup   

Step: 3
Add these lines in wslservices.bat and save it.

wsl sudo service ssh start
wsl sudo service apache2 start
wsl sudo service mysql start

After restarting the host of WSL, services it will be start automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment