Unable to change the root password in Windows 10 WSL
Solution 1:
There is a simpler method.
- Open cmd.exe
- Type
wsl -u root
- Type
passwd username
and change the password - Type
exit
- Type
wsl
- Type
sudo echo hi
to confirm the new password works.
Solution 2:
- in wsl,
sudo passwd
will change the password of the WSL root user. - in wsl,
passwd
will change the password of the current WSL user
- to specify which WSL user to use (temporarily)
wsl -u [user]
- in wsl,
passwd [user]
will change the password of any WSL user - in wsl,
sudo
generally asks for the password of the current WSL user. - in windows cmd.exe, you can change the default WSL user (permanently):
- in current versions:
ubuntu.exe config --default-user [user]
- in legacy versions
1703
,1709
:lxrun /setdefaultuser [user]
- a restart may be required
You probably want to change the password of the sudo
-capable, non-root user.
You probably do not want to change the root users password (because in Ubuntu, the root user generally should not have a password, sudo
should be used instead).
You probably also do not want to leave your default user as root. Even when working form windows, its still a bad practice.
Official Microsoft documentation on User Accounts and Permissions can be found here: https://msdn.microsoft.com/en-us/commandline/wsl/user_support
Solution 3:
It is assumed you are using Ubuntu in this explanation.
- If you forgot your password on WSL simply open your command prompt from windows by typing cmd on search.
- Then type
ubuntu config --default-user root
to set root as the default user for Linux Bash Shell. - Then open the Linux Bash shell which will log you in as root without asking for password.
- Then use
passwd username
to reset the password of any user. - Use
ubuntu config --default-user username
to reset back to your normal Linux user account.