Automatically starting the SSH service on WSL (v1 or v2)

Nelson Aloysio
1 min readSep 13, 2022
Figure: New basic task to start the SSH service automatically on user login.

Pretty simple, but I recently lazily searched for it on the web and the solutions I found were a bit convoluted (writing and saving a batch script to run a Visual Basic script that would in turn start a program in Bash…).

Open up the Task Scheduler and choose the action to Create Basic Task, then simply set it up to execute the following line on user login:

wsl.exe -u root -- service ssh start

And presto! From now on, SSH will automatically start when a user logs in.

Tweaking the task

A few additional tweaks can be done in the Conditions and Settings tabs of the newly created task, e.g., to make it always start regardless of the computer AC state (if you are using a portable), among other choices:

Figure: “Start the task only if the computer is on AC power” is usually enabled by default in Conditions.

All in all, pretty basic stuff, but that might be worth checking out.

--

--