How to reset your forgotten Linux password in WSL

Contents

Forget the Windows subsystem user password for Linux and you will be stuck in a loop. To reset your password … you need to know your password. Here's how to escape that cycle.

Locked in an endless loop

An ouroboros is an ancient symbol that represents a snake or dragon that eats its own tail. If you forget your Windows Subsystem for Linux (WSL) of user, you will find yourself locked in an equally nasty and endless loop.

The first time you start a newly installed Linux distribution under WSL, you will be asked to provide a username and password. This is your user password. In a normal Linux installation, you are prompted for your password each time you log in. Despite this, con WSL, your user logs in automatically and takes you directly to the Linux command prompt.

Because you don't need to use your password to log in, it's easy to get out of your mind. Especially if you don't use WSL many times.

That may not seem like a setback because, after all, log in automatically. The problem becomes apparent when you try to access files that are not within your home directory, install software, or perform administrative activities such as creating and managing other users.

To do those things, you need to use the sudo command. En Linux, demonstrates that you are authorized to use sudo command providing your password.

The obvious solution is to reset your password. You forgot it, therefore set a new one, truth? It's a great idea. But passwd command needs your Current password to show that it is you. It's a sensible security measure. the passwd The command needs proof that you are the owner of the user account for which you are changing the password before it will allow you to go ahead and change the password.

If you use sudo with the passwd command can change password of any user whether you know their password or not. That sounds like a solution, but we are still frustrated because using the sudo command need to know your password. This starts to feel like an ouroboros and a 22 catches set.

There are alternatives to escape from this circular logic puzzle, of course. Here are two that you can try.

Reset with Linux executable

We will show you two alternatives to do this. One way is a bit more complicated than the other, but it has worked every time we have tried it. The other way is a slightly simpler method, but we have had mixed results.

We need to identify the executable file for the Linux distribution you are using with WSL. In Windows 10 will be in this directory:

c:user<username>AppDataLocalMicrosotWindowsApps

Replace “” with the name of your Windows user account. At a Windows command prompt, change the directory to this location, then type “to you”.

to you

dir in a command window

Executable should be easy to identify. On this test machine, we have installed Ubuntu 20.04, and the file "ubuntu2004.exe" is evidently what we are looking for.

We will start an Ubuntu session, but we will instruct you to log in as root user instead of the user account you created when you installed the Linux distribution.

ubuntu2004 config --default-user root

An Ubuntu session is started and we are presented with the command prompt in a terminal window. The message is in white text and the final character is a pad “#”, not a dollar sign “$”. That tells us that the user is the root user and not a normal user. The username also spells “root”.

If further testing is required, we can use the whoami command.

whoami

Then, we are definitely logged in as root. We can go ahead and reset the default user password. the passwd The command will ask for your new password and then it will ask you to enter it a second time. Neither of us will echo on the screen. The password we are changing belongs to the user “dave”.

passwd dave

Make sure you remember what the new password is. We will exit the Ubuntu session and return to the Windows command prompt.

exit

To test our new password, we need to start a new Ubuntu session and reset the normal user account as the default account.

ubuntu2004 config --default-user dave

The session starts and we log in as the normal user, with our frequently colored command prompt.

To prove that our password has been changed we will use the sudo command in a command. The command we use does not matter, is the fact that we are using sudo that is essential. We will use the ps command to list some processes.

sudo ps -e

You will be prompted for the password you created when you used the passwd command as root. The password should be accepted and the command should start automatically.

Reset with the wsl command

We can achieve the same using the WSL command. In our tests, we got inconsistent results, but it is possible that he has more luck than us. This is a shorter method, so you may want to try it first and, if it doesn't work for you, try the longer method we previously showed you.

At a Windows command prompt, scribe:

wsl --user root

wsl: root user in a command window

A Linux session will start. You will be logged in as root. You can verify this using the whoami command.

whoami

To reset the forgotten user password, Use the passwd command and provide the name of the user account.

passwd dave

You will be asked to provide the new password twice. And that should be it.

If you log out of this session and start a new session, you will log back in as the normal default account and have a new password.

Stop biting your tail

One or both of these techniques will work for you., and you will be freed from the endless cycle of not being able to reset your password due to not knowing it.

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.