menuhin
New member
Scenario: I want to start some services that is provided by the installed distribution on WSL2 (Debian), e.g. sshd etc.
Solution 1:
Solution 2:
Question 1: In either case, WSL is not called to start up (solution 1 calls wsl.exe to run a command and solution 2 calls bash.exe to run a file within the WSL installation) - why these both works without directly calling WSL to start first?
Question 2: how about the normal services under /etc/init.d/ - will these services automatically run as long as WSL is started up, even not manually? And if no, why?
Solution 1:
- Set up sshd on distro of choice. Ensure it works (firewall set up properly, etc.) when launched manually
- Ensure that the distro which will run sshd is the default distro (use wslconfig)
- Create a task using Task Scheduler (taskschd.msc) that has the action "Start a program", with the program set to wsl with optional arguments -u root service ssh start
- Set the task to run on computer startup. Specify a user account to run the task as, and specify that the task run whether or not the user is logged in
Solution 2:
- On the WSL put to the end of the /etc/sudoers file the following line:
%sudo ALL=NOPASSWD: /etc/init.d/ssh start - Put to the shell:Startup folder bat file with the content:
powershell.exe "& 'C:\Windows\System32\bash.exe' -c 'sudo /etc/init.d/ssh start'"
Question 1: In either case, WSL is not called to start up (solution 1 calls wsl.exe to run a command and solution 2 calls bash.exe to run a file within the WSL installation) - why these both works without directly calling WSL to start first?
Question 2: how about the normal services under /etc/init.d/ - will these services automatically run as long as WSL is started up, even not manually? And if no, why?
My Computer
System One
-
- OS
- Windows 11, WSL2 Debian
- Computer type
- Laptop
- Manufacturer/Model
- Lenovo ThinkPad X220 Tablet
- CPU
- Intel Core i7-2640M CPU @ 2.80GHz 2.80 GHz
- Memory
- 8 GB
- Monitor(s) Displays
- (external) Monitor Lenovo LT2452P, 24" IPS LED, 1920 x 1200
- Screen Resolution
- 1366 × 768