An Easy Method for Resetting Your Linux Password on WSL
Tags: beginners, codenewbie
Published: 2022-09-13 15:46:55

 Ok, so I was totally going to write this post about some of the flags you can use when using rails g to make files for your project.  However, while working on a new project I needed to use a sudo command that required my password and I had forgotten it. I wish I could say this was the first time that I had to reset my password but seeing as this was not I figured I might as well save some folk a bit of searching a trouble as this is what has worked well for me. 

When you installed Linux using WSL in Windows you are asked to create a username and password.  This user is automatically logged on whenever you start Linux on WSL, so if you forget your password its not so important unless you need to do something like run a sudo command. I personally use Ubuntu and have verify that these steps have worked for me and I believe that should work for other Linux distributions on WSL as well.

Steps:
1. Switch the default user to root
2. Reset the password for the normal user
3. Switch the default user back to the normal user

## Step 1: Switch the default user to root

Before switching the default user to root it would be best if you took note of your account's normal username. (You need this to reset your password and set the default back)

Switching to the root user is done through the Windows Command Prompt. Which command you run will depend on your Linux distribution. This information can usually be found in the description of the app in the Widows Store. 

Open the command prompt from the Windows start menu. You can find it by searching for cmd in the search bar. 

In the command prompt you would enter your distribution's command. For me using Ubuntu it was:

`ubuntu config --default-user root`

Here are some other commands for other common distributions:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1r43u3a7p8e13l90ypk.jpg) image credit:https://itsfoss.com/reset-linux-password-wsl/

## Step 2:Reset the password for the normal user

Now reopen your Linux distribution app and you should be logged on as root. At this point we can rest the password for the normal user account. Use the following command with the username you hopefully noted down earlier:

`passwd username`

It will ask you to enter a new password. When you type here, nothing will be displayed on the screen. That’s normal. Just type the new password and hit enter. You’ll have to retype the new password to confirm and once again, nothing will be displayed on the screen while you type the password. 

Hurrah! This should have reset your password. You are almost ready to move forward with well, whatever you were doing before you had to plunge down this rabbit hole...

## Step 3: Switch the default user back to the normal user 

For the final step you will need your username associated with the password you just reset and the command prompt again.  

Start the Windows command prompt for your distribution as you did in Step 1. You will be using a similar command to the one we used to switch to root. This time we will be replacing root with whatever your specific username is. Remember to use the prefix specific for your distribution. So for me it was:

`ubuntu config --default-user username` 
 
Now the reopen your distribution app and you should be logged on the the normal user. Your new password should be working and you should be good to go with running your sudo commands. If you forget your password again, you can now reset it with a few steps. Hopefully, this was useful for you to get back on your coding journey. Happy Coding!