How to reset WSL user password

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 regular Windows application.

On WSL, password forgetting is handled differently than in a normal Linux environment, as there is no editable bootloader. It also doesn't have an init system that you can hijack to launch a root shell. This guide will show you the steps to reset WSL user password.

Use root account

A simple way to recover or reset forgotten passwords for WSL users is to use the root account. In most WSL distributions, the root account is enabled and no password is required.

Since WSL automatically logs in to the default account set without a password prompt, you can change the configuration file and set the default account as the root account.

To change the configuration, it is necessary to use the WSL version executable. By default, the executable is located in

C:usersusernameappdataLocalMicrosoftWindowsApps.

Replace username with your user account name and distroname with your WSL distribution. For example, the openSUSE 15.3 Leap executable would be

C:UsersmteAppDataLocalMicrosoftWindowsAppsopenSUSE-Leap-15.3.exe.

To change the configuration for the distribution, launch the Command Prompt and enter the command that matches the name of your distribution. 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 the WSL openSUSE instance.

For other distributions, the command would be:

Ubuntu

ubuntu config --default-user root

Ubuntu 18.04

ubuntu18004 config --default-user root

Ubuntu 20.04

ubuntu2004 config --default-user root

Kali Linux

kali config --default-user root

Debian

debian config --default-user root

Arch Linux

arch config --default-user root

The final step is to login to the distribution and change the password for the target username. You can launch your distro using the Start menu, Command Prompt, or selecting it from the Windows Terminal.

Picture 1 of How to reset WSL user password

After launching, you should log in as root.

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

passwd cap

Restore default user

After you reset the password for a specific user, it is best to change the default user instead of using the root account.

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

opensuse-leap-15.3 config --default-user cap

Remember to replace it with your distribution's name.

Hope you are succesful.

Update 31 July 2021
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile