In a standard Linux environment (either on a virtual machine or bare metal), you can make tweaks from the GRUB and reset it if you forget your password.
On WSL, things tend to be slightly different because it does not contain a bootloader for you to edit. It also does not feature
init system, which you can hijack to launch a root shell.
However, this does not mean you need to uninstall and re-install your WSL instance to reset a forgotten password. This guide walks you through simple steps to reset your password in WSL instances.
Using the root account.
A simple method to recover or reset a forgotten password for a WSL user is to use the root account.
In most WSL distributions, the
root account is enabled and does not have a password set for it.
Since WSL automatically logs in to the set default account without a password prompt, we can change the configuration file and set the default account as root.
To change the configuration, we need to use the WSL instance executable. By default, the executable file is located in
NOTE: Replace the username with your account username and the distribution name with your WSL distro.
For example, the openSUSE 15.3 Leap executable would be
To change the configuration for the distro, launch the command prompt and enter the command matching your distribution name.
For example, for openSUSE, set the default user to root with the command:
opensuse-leap-15.3 config --default-user root
The above command will change the default user to root for openSUSE WSL instance.
For other distributions, the commands are as shown:
ubuntu config --default-user root
ubuntu18004 config --default-user root
ubuntu2004 config --default-user root
kali config --default-user root
debian config --default-user root
arch config --default-user root
The final step is to log in to your distribution and change the password for your target username.
You can launch your distribution using the start menu, the command prompt, or selecting it from the Windows terminal.
Once you launch it, you should be logged in as root.
Finally, use the passwd command to change the password.
For example, to change the password for the
geekbits username, set the command:
Restore default User
Once you reset the password for the specific user, it is recommended to change the default user instead of the root account.
Use the config command and replace the username with your desired account.
opensuse-leap-15.3 config --default-user cap
Remember to replace it with your distribution name.
This tutorial describes straightforward steps to reset the password for a WSL user. The steps discussed in this tutorial are simple and do not pose much threat to your WSL instances. However, always secure your systems in case of compromise.