WSL asks you for a user name and a password once, the first time a distribution starts, and then never again, which is exactly why people forget the password and why the question "which user am I in WSL?" has so many wrong answers online. This post creates a throwaway Ubuntu 24.04 distribution on WSL 2.7.10, works out where the default user comes from, changes it both ways, resets a forgotten sudo password from Windows, and looks at root's password, with every command's output quoted. Nothing here touched the PC's real distribution.
wsl --install Ubuntu-24.04 --name wslfix --no-launchinstalls a second copy under a new name, about 33 seconds, no Store promptwsl -d wslfix -- id: you are root, because the first-run script that creates the normal user has not run- Create a user as root, then set
[user] default=mariain/etc/wsl.conf, runwsl --terminate wslfix, and checkidagain - Try the newer
wsl --manage wslfix --set-default-user maria, which needs no restart - Type a wrong sudo password, then reset it from Windows with
wsl -d wslfix -u root wsl --unregister wslfixremoves the distribution and its disk
Where the default user comes from
A distribution installed with --no-launch and opened with a plain command is root:
uid=0(root) gid=0(root) groups=0(root)
The normal user does not exist yet. The distribution's /etc/wsl-distribution.conf names a
first-run script, /usr/lib/wsl/wsl-setup, with defaultUid = 1000, and that script
is what prompts "Create a default Unix user account:" the first time you open a terminal. It creates
the user with adduser and the groups adm,cdrom,sudo,dip,plugdev; the
sudo group is why that account can administer the distribution. The PC's real
distribution shows the result of that script: uid 1000, those groups, plus users. WSL also
keeps a DefaultUid value per distribution in the Windows registry; after this install it
was 0.
Changing the default user, both ways
Create the user as root (the password is the test's):
useradd -m -s /bin/bash -G sudo maria && echo 'maria:Clinic-2026' | chpasswd && id maria
uid=1000(maria) gid=1000(maria) groups=1000(maria),27(sudo)
The documented way to make her the default is the [user] section of
/etc/wsl.conf, with default=maria. It takes effect only after the
distribution stops: the documentation's "8 second rule" says changes appear once every shell is
closed and the distribution has shut down, and wsl --terminate wslfix does that at once.
After the terminate, id printed maria. The registry value stayed 0; wsl.conf does not
write it.
WSL 2.7.10 also has a command for it, which the two documentation pages do not mention yet:
wsl --manage wslfix --set-default-user maria
The operation completed successfully.
That one took effect on the very next command, with no restart, and set the registry value to 1000.
When the two disagree, the file wins: with the registry pointing at maria and wsl.conf at a second
user, the next command still ran as maria, and after a terminate it ran as the user in the file.
Store-installed distributions have a third way, a launcher such as ubuntu2404.exe with a
config --default-user option; this PC has no Store install, so that route was not run.
The forgotten sudo password
Here is what the user sees when the password is wrong:
[sudo] password for maria: Sorry, try again.
[sudo] password for maria:
sudo: no password was provided
sudo: 1 incorrect password attempt
The fix needs no Linux password at all, because Windows can start a process inside the distribution
as any user. The documentation's recipe is wsl -d <DistroName> -u root followed by
passwd <username> at the root prompt. Run from PowerShell, the first half proves the
point:
wsl -d wslfix -u root -- whoami
root
No prompt. The test set the new password non-interactively with
echo 'maria:NewPass-2026' | chpasswd as root, after which sudo accepted the new
password and refused the old one. Why does -u root work without a password? A WSL
distribution is, in the documentation's words, a per-user installation: it is registered under your
Windows account, its disk lives under your profile, and wsl.exe starts the process you ask
for as the user you name. No Linux login step was seen in the run; the Linux password guards changes
made from inside Linux, such as sudo and su, not the way in from Windows. That
also means anyone who can run commands as your Windows user is root in your distributions.
Root's own password
People search for "WSL root password". The status line answers it:
root L 2026-09-08 0 99999 7 -1
L means locked: root has no usable password, and su - from the normal user
fails with Password: su: Authentication failure whether you type the user's password or
nothing. You never need it. Use sudo from the default user inside Linux, or
wsl -u root from Windows.
Two things that bite scripts
- sudo without
-Shangs from PowerShell.wsl -d wslfix -- sudo truedid not fail;wsl.exegave it a pseudo-terminal, the password prompt went there, and the command waited for three minutes until the distribution was terminated. In a script, run as root with-u rootor pipe the password withsudo -S. - Captured
wsloutput looks like UTF-16. In PowerShell the text came out with a space between every letter until$env:WSL_UTF8='1'was set before the call.
Frequently asked
- How do I reset a forgotten WSL sudo password?
- From PowerShell, open the distribution as root with wsl -d <DistroName> -u root (or wsl -u root for the default distribution); no Linux password is asked, because the distribution belongs to your Windows account. Then run passwd <username>, type the new password twice, and exit. The new password works with sudo at once and the old one is refused.
- How do I change the default user in WSL?
- Add a [user] section with default=<username> to /etc/wsl.conf inside the distribution, then stop it with wsl --terminate <DistroName>; the next command runs as that user. WSL 2.7 also has wsl --manage <DistroName> --set-default-user <username>, which takes effect immediately. If both are set, the wsl.conf value wins once the distribution restarts.
- What is the root password in WSL?
- There is none: root's account is locked, and su fails with Authentication failure. Use sudo from the default user inside the distribution, or start a root shell from Windows with wsl -u root, which needs no password because WSL distributions are a per-user installation under your Windows account.
The error itself, "Sorry, try again" after a forgotten password, has a Fixes post. For what WSL does with ports shared between Windows and Linux, see Ollama ports, OLLAMA_HOST and 11434.