How to Reset a WSL User Password

Reset Wsl Featured

Windows Subsystem for Linux, commonly known as WSL, is a feature that allows users to run supported Linux distributions in Windows. Unlike dual boot, WSL runs inside Windows like a typical Windows application. On WSL, forgotten passwords are handled differently than a normal Linux environment because it does not have a bootloader that you can edit. It also does not have an init system that you can hijack to launch a root shell. This guide walks you through the steps to reset your WSL user password.

Using the Root Account

A simple way 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.

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 in “C:\users\username\appdata\Local\Microsoft\WindowsApps\<distroname.exe>”

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: “C:\Users\mte\AppData\Local\Microsoft\WindowsApps\openSUSE-Leap-15.3.exe”

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:

The above command will change the default user to root for the openSUSE WSL instance.

For other distributions, the commands are:

Ubuntu

Ubuntu 18.04

Ubuntu 20.04

Kali Linux

Debian

Arch Linux

The final step is to log in to your distribution and change the password for your target username. You can launch your distribution by using the Start menu, the command prompt, or selecting it from the Windows terminal.

Launch Wsl Terminal

Once you launch it, you should log in as root.

Finally, use the passwd command to change the password. For example, to change the password for the cap username, set the command as:

Restore Default User

Once you reset the password for the specific user, it’s best to change the default user instead of the root account.

To do that, use the config command and replace the username with your desired account. For example:

Remember to replace it with your distribution name.

Wrapping Up

This tutorial shows you the steps to reset a WSL user password. The steps discussed in this tutorial are simple and safe for your WSL instances. However, it’s good practice to secure your systems. If you have decided to switch to Linux for good, check out the best Linux distros for Windows users here, or learn how to move from Windows to Linux the easy way.

John Wachira

John is a technical writer at MTE, when is not busy writing tech tutorials, he is staring at the screen trying to debug code.

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.