How to Change the Default User in WSL

🐧Part of the WSL Complete Guide, every Windows Subsystem for Linux post on this site, organised by task.
The short answer

Run wsl --manage <Distro> --set-default-user <Username> from PowerShell. No config file editing required.

WSL logs you in as the account you created when the distribution first started. That is fine until you want it to open as root for setup work, or you created the account with a typo and have been living with it ever since.

Change It

# see the distro names exactly as WSL knows them
wsl -l -v

# set the default user for one distribution
wsl --manage Ubuntu --set-default-user peter

# log in as root instead
wsl --manage Ubuntu --set-default-user root

The change applies the next time you start that distribution. If a session is already open, close it, or run wsl --terminate Ubuntu first.

The Older Methods You Will Find Online

Most guides still describe one of two older approaches, and both still work:

# 1. the distro launcher
ubuntu config --default-user peter

# 2. /etc/wsl.conf inside the distribution
[user]
default=peter

The launcher method needs the executable name to match your distro, which is fiddly once you have several. The wsl.conf method means editing a file inside a distribution you might not be able to log into, which is awkward precisely when you need it most. The --manage command avoids both problems.

The account has to exist inside the distribution first. Setting a default user that Linux does not know about leaves the distro failing to start. If that happens, set it back to root with the same command, then create the account properly with adduser.

Related


If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Looking for SQL Server?

This site started as a SQL Server blog in 2017 and the archive is still here. The new SQL Server writing, and all the scripts, moved to a site of their own.

sqldba.blogScripts, error library, wait types, SSMS
Browse by topic