Linux Windows Compatibility

How to Reset Forgotten WSL Password

Windows Subsystem for Linux (WSL) is a Windows feature that enables users to spawn a complete Linux environment directly from the Windows operating system.
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:

  1. Ability to choose from various popular Linux distributions such as Ubuntu, Debian, OpenSUSE, Kali Linux, etc.
  2. Run native Linux applications as if they were native Windows apps.
  3. Write and execute scripts on the Linux environment without any modifications.
  4. Setup native Linux development tools.
  5. Browse WSL Linux filesystem using the default Windows file explorer.
  6. 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:

  1. Configure WSL to use the root user as default.
  2. Reset the password for the default WSL username
  3. 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:

C:\Users\\AppData\Local\Microsoft\WindowsApps

NOTE: The username denotes the default Windows system username.

For example, the executable for Debian is in:

C:\Users\linuxhint\AppData\Local\Microsoft\WindowsApps\debian.exe

In the command prompt, cd into the directory of the Linux executable file. For example:

cd C:\users\linuxhint\AppData\Local\Microsoft\WindowsApps

Next, set the default user for your distribution using the command:

distroname.exe config --default-user root

Replace distroname.exe with the actual executable for your Linux distribution as:

debian.exe config --default-user root

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.

passwd <default_username>

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:

distroname.exe config --default-user

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!

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list