Auto-Starting WSL2 on Windows Boot¶
WSL2 does not start automatically when Windows boots. You need something on the
Windows side to launch wsl.exe, which then triggers the Linux instance.
Method 1: Task Scheduler at Logon (RECOMMENDED)¶
Reliable, well-tested, runs after user login.
Setup via GUI¶
- Open
taskschd.msc(Task Scheduler). - Create Task (not "Basic Task").
- General: Check "Run with highest privileges".
- Trigger: "At log on" for your user account.
- Action: Start a program:
- Program:
C:\Windows\System32\wsl.exe - Arguments:
-d Ubuntu -u root -- /bin/bash -c "service ssh start && sleep infinity" - Settings: Uncheck "Stop the task if it runs longer than".
Setup via PowerShell¶
$action = New-ScheduledTaskAction -Execute "C:\Windows\System32\wsl.exe" `
-Argument "-d Ubuntu -u root -- /bin/bash -c `"service ssh start && sleep infinity`""
$trigger = New-ScheduledTaskTrigger -AtLogOn
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero)
Register-ScheduledTask -TaskName "WSL2-AutoStart" -Action $action `
-Trigger $trigger -Settings $settings -RunLevel Highest
Method 2: VBScript in Startup Folder¶
Place a .vbs file in shell:startup (press Win+R, type shell:startup):
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "wsl.exe -d Ubuntu --exec dbus-launch true", 0, True
The 0 hides the window. dbus-launch true keeps the instance alive.
Limitation: Only runs after user login, same as Task Scheduler at logon.
Method 3: Task Scheduler at Startup (Pre-Login)¶
Technically possible but has known session isolation bugs. WSL2 started
before user login creates a separate session context. When the user later
logs in, interop breaks:
- \\wsl.localhost\ becomes inaccessible in Explorer
- PowerShell wsl commands get "PathNotFound" errors
- GUI apps fail
Only suitable for purely headless/SSH-only scenarios where nobody ever logs into the Windows desktop. If the PC at your brother's might be used interactively, avoid this method.
Method 4: NSSM (Windows Service Wrapper)¶
NSSM wraps wsl.exe as a proper Windows service:
# Install: choco install nssm
nssm install WSL-SSH "C:\Windows\System32\wsl.exe" "-d Ubuntu -u root -- service ssh start"
nssm set WSL-SSH Start SERVICE_AUTO_START
nssm start WSL-SSH
Same pre-login session isolation caveats apply.
Method 5: wsl.conf [boot] command (requires WSL to be launched first)¶
This fires when WSL2 starts, not when Windows boots. Useful as a complement to Methods 1-4, not as a standalone solution.
Best practice: Combine Method 1 (Task Scheduler triggers WSL launch) with this (sshd starts automatically when WSL launches).
Important: Remote Desktop / Auto-Login Consideration¶
If the PC at your brother's will stay logged in (e.g., auto-login configured), Task Scheduler at logon is the simplest and most reliable approach. Configure Windows auto-login:
# PowerShell (admin) -- sets auto-login for current user
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Set-ItemProperty -Path $RegPath -Name "AutoAdminLogon" -Value "1"
Set-ItemProperty -Path $RegPath -Name "DefaultUserName" -Value "<username>"
Set-ItemProperty -Path $RegPath -Name "DefaultPassword" -Value "<password>"
With auto-login + Task Scheduler at logon, WSL2 starts automatically after any reboot without requiring someone to be physically present.