DEV Community

How to Change the Default User of an Imported WSL Distro

An imported WSL distribution often starts every session as root. That is useful during a recovery, but it is a poor everyday default: root can change anything without a sudo prompt, and tools that expect your normal home directory may behave differently.

This guide shows how to identify the right WSL instance, choose the correct default-user mechanism for how that instance was installed, and verify the change. You do not need to reinstall the distro or edit the Windows registry.

Table of Contents

  • Confirm the distribution name and current user
  • Choose the right method for your distribution
  • Set the default user with wsl --manage
  • Set the default user in /etc/wsl.conf
  • Use the launcher only for Store-installed distributions
  • Restart and verify the change
  • Troubleshoot a change that does not stick
  • Conclusion

Confirm the distribution name and current user

Open PowerShell or Windows Terminal and list your registered distributions:

wsl --list --verbose

The NAME column is the identifier to use with every command below. It may differ from the friendly name shown in the Start menu. For example, the Ubuntu app can appear as Ubuntu 24.04 LTS, while the registered WSL instance is Ubuntu-24.04.

Check which user the instance actually starts as:

wsl -d Ubuntu-24.04 -- id -un

If the output is root, the instance has no normal default user recorded, or its default is still set to root. If it already prints your account name, the default is correct and the problem is somewhere else.

Ubuntu's own documentation for restored or imported instances notes that without a user specified, you will be logged in as root. That is the behavior this guide fixes.

Choose the right method for your distribution

There are three supported routes, but they are not interchangeable. The key question is whether the distribution has an executable launcher.

How the distribution was installed Best first choice Why
Microsoft Store or wsl --install .exe config --default-user The launcher exists and updates the stored default login.
Imported with wsl --import, or restored from a tar or VHD wsl --manage --set-default-user on WSL 2.4.10 or later; otherwise /etc/wsl.conf Imported distributions have no launcher, so the launcher command cannot work.
Renamed, moved, or cloned instance wsl --manage or /etc/wsl.conf The old launcher alias may no longer match the registered instance.
Older WSL build or --manage is unrecognized /etc/wsl.conf It is per-distribution and does not depend on the newer CLI option.

Microsoft's WSL command reference gives the familiar launcher command, but it explicitly warns that the command will not work for imported distributions because they do not have an executable launcher. That warning is the reason imported distros need a different route.

The username must also be an existing Linux account inside the distribution, not your Windows username. You can confirm it from a root session:

wsl -d Ubuntu-24.04 -u root -- getent passwd alice

A line beginning with alice: means the account exists.

Set the default user with wsl --manage

Recent WSL releases include a direct command for this. The ArchWiki WSL installation guide documents the syntax and notes that WSL 2.4.10 or later is required:

wsl --manage Ubuntu-24.04 --set-default-user alice

The change takes effect the next time the distribution starts. Check your WSL version first if you are unsure:

wsl --version

If --manage or --set-default-user is not recognized, your WSL build is older than the option or the command is unavailable. Use the /etc/wsl.conf method below instead of guessing at a different command.

Set the default user in /etc/wsl.conf

This is the portable method and the one Microsoft documents for imported distributions. The wsl.conf file lives inside the Linux distribution, not on the Windows side, and its [user] section controls which account a new WSL session runs as.

Microsoft's advanced settings reference says the default key specifies the user to run as when first starting a WSL session, and that the option is available in Windows 10 build 18980 and later. It also explains the "eight-second rule": configuration changes only appear after the subsystem running the distribution has completely stopped.

Open a root shell for the target instance:

wsl -d Ubuntu-24.04 -u root

Then edit the configuration file:

nano /etc/wsl.conf

Add the section, using the existing Linux username:

[user]
default=alice

If the file already contains a [user] section, change the existing default= line instead of adding a second section. Save the file and exit the editor.

If you prefer to create the file in one command when it does not exist, use:

tee /etc/wsl.conf > /dev/null << 'EOF'
[user]
default=alice
EOF

Do not run that command if /etc/wsl.conf already has content, because it replaces the whole file.

Use the launcher only for Store-installed distributions

Store-installed distributions have a Windows executable launcher, such as ubuntu.exe or ubuntu2404.exe. The launcher accepts the config --default-user command:

ubuntu2404.exe config --default-user alice

Use the actual launcher filename for your installed app. If PowerShell says the command is not recognized, the launcher is missing from your path or the distribution does not have one. In that case, return to wsl --manage or /etc/wsl.conf.

This is the method to skip for imported, restored, or cloned distributions. It is also unreliable for a renamed instance, because the launcher alias and the registered WSL name can diverge.

Restart and verify the change

Terminate only the distribution you changed, then start it again:

wsl --terminate Ubuntu-24.04
wsl -d Ubuntu-24.04 -- id -un

The second command should print alice. If it still prints root, do not keep opening new sessions; go to the troubleshooting section below.

For a full interactive check, start the distribution and run:

whoami
sudo whoami

whoami should print alice. sudo whoami should ask for Alice's Linux password and then print root. That confirms both the default login and administrative access.

You can also check group membership from inside the distro:

groups

The output should include sudo for an Ubuntu account that is meant to administer the system.

Troubleshoot a change that does not stick

The change is ignored after restart

WSL may still be running in the background. Microsoft's reference says configuration updates are picked up only after the subsystem stops, which typically takes about eight seconds after closing all instances. Use wsl --terminate Ubuntu-24.04 to stop just that distribution, then relaunch it.

Also inspect the file for duplicate or conflicting [user] sections:

wsl -d Ubuntu-24.04 -u root -- cat /etc/wsl.conf

Keep one [user] section with one default= line. If you have both a wsl.conf setting and a launcher-set default, remove the stale one rather than layering multiple mechanisms.

The username is wrong or missing

Confirm the account exists and the spelling matches exactly:

wsl -d Ubuntu-24.04 -u root -- getent passwd alice

If there is no output, create the account from the root shell:

wsl -d Ubuntu-24.04 -u root
adduser alice
usermod -aG sudo alice

Then set the default user again. On Ubuntu, adduser is the interactive wrapper; other distributions may use useradd with different defaults.

The launcher command fails

This is expected for imported distributions. Microsoft's documentation says the launcher route does not work when there is no executable launcher, and imported distributions do not have one. Use wsl --manage on a recent WSL build, or edit /etc/wsl.conf.

Root keeps coming back

Do not set root as the permanent default just because it is convenient during recovery. Use a temporary root session instead:

wsl -d Ubuntu-24.04 -u root

Repair what you need, then restore the normal account with one of the methods above. If the only account in the distribution is root, create a normal user and add it to the sudo group before changing the default.

The default user is correct but sudo still fails

If whoami shows the right account but sudo rejects the password you expect, the problem is the account password or sudo configuration, not the default-user setting.

Conclusion

An imported WSL distribution starts as root because the import has no normal default user recorded. The fix is to choose the mechanism that matches the installation: use wsl --manage <Distro> --set-default-user <user> on WSL 2.4.10 or later, or add [user] default=<user> to /etc/wsl.conf as the portable fallback. Keep the launcher command for Store-installed distributions that still have a working executable.

After the change, terminate the distribution, relaunch it, and verify with whoami and sudo whoami. Root remains available for temporary recovery sessions through wsl -d <Distro> -u root, but it should not be the everyday login.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.