WSL root access and password reset¶
WSL (Windows Subsystem for Linux) allows users to run a Linux environment alongside Windows. Managing user access, particularly for the root user, is a common administrative task that can be performed directly via PowerShell or the Windows Command Prompt.^[600-developer-tools-windows-wsl-command.md]
Root login¶
To switch the current session context to the root user, use the -u root flag when launching a specific distribution.^[600-developer-tools-windows-wsl-command.md]
wsl -d <DistributionName> -u root
For example, to log in as root for a distribution named "U20.04-tommy":^[600-developer-tools-windows-wsl-command.md]
wsl -d U20.04-tommy -u root
Password reset¶
Once you have accessed the system via the root user (as shown above), you can change the password for any user using the standard Linux passwd command.^[600-developer-tools-windows-wsl-command.md]
passwd <username>
To change the root password itself:^[600-developer-tools-windows-wsl-command.md]
passwd root
Default user configuration¶
To ensure that the WSL distribution launches with a specific standard user (rather than root) by default, you can modify the /etc/wsl.conf file.^[600-developer-tools-windows-wsl-command.md]
- Switch to the root user.
- Append the default user configuration to the file. Replace
$myUsernamewith the target username.
bash
echo -e "[user]\ndefault=$myUsername" >> /etc/wsl.conf^[600-developer-tools-windows-wsl-command.md]
Related Concepts¶
- [[PowerShell]]
- [[Linux command line]]
- [[WSL]]
Sources¶
^[600-developer-tools-windows-wsl-command.md]