WSL provides a complete Linux instance including all native utilities, tools, and applications without using technologies such as virtual machines or Windows/Linux dual boot setup.
Notable features of the Windows Subsystem for Linux include:
- Ability to choose from various popular Linux distributions such as Ubuntu, Debian, OpenSUSE, Kali Linux, etc.
- Run native Linux applications as if they were native Windows apps.
- Write and execute scripts on the Linux environment without any modifications.
- Setup native Linux development tools.
- Browse WSL Linux filesystem using the default Windows file explorer.
- Deployment of WSL environment from tools such as Visual Studio Code
The purpose of this guide is to show you how to reset a forgotten user’s password for any WSL Linux instance.
NOTE: This tutorial only works if the forgotten password is not for the root user.
How the Functionality Works
Before diving into the commands and resetting a forgotten password, let us discuss how this functionality works.
The first time you launch your WSL instance, it will prompt you to configure a username and password.
WSL will use the configured username and password to log you into your Linux environment automatically. Although this is a handy feature, if you forget your username’s password, you cannot invoke any commands that require a password.
Resetting WSL Password
To reset the forgotten password for your WSL instance, we will perform the following operations:
- Configure WSL to use the root user as default.
- Reset the password for the default WSL username
- Restore the default username.
Configure Root As The Default Account
Previously, we mentioned that WSL automatically logs in with the set default account. In most cases, you will have to configure the default account during the installation of your WSL Linux instance.
However, we can use the WSL Linux executable command to set the default user as the root account, forcing WSL to log in to the Linux environment without prompting us for a password.
Launch the command prompt on your Windows system.
Next, locate the path to the executable of your Linux distribution. By default, the executable files for your install Linux distributions are in:
NOTE: The username denotes the default Windows system username.
For example, the executable for Debian is in:
In the command prompt, cd into the directory of the Linux executable file. For example:
Next, set the default user for your distribution using the command:
Replace distroname.exe with the actual executable for your Linux distribution as:
Change the Password For Your Default Username
Launch your WSL Linux distribution, and you should be dropped into a root shell automatically.
The next step is to use the passwd command to reset the forgotten password.
Replace default_username with your actual WSL instance username. You can check /etc/passwd to see your username.
Next, enter the new password for your specified username.
Restore Default Username
Once you set a new password for your username, you need to restore the default login username from the root account.
Enter the command:
Now you should be logged into your WSL instance as the specified user.
Closing
This guide covers how to reset a forgotten password for any WSL Linux instance.
Thank you for reading!