Reset the password in Ubuntu / Linux Bash in Windows

Solution 1:

  • Run bash and make a note of your Linux username (this need not match your Windows username), see How can I find out my user name?
  • Close Bash on Ubuntu if it is running (or the next command will fail).
  • In Windows admin command prompt (Super+X, A) change the default user to root:

    ubuntu config --default-user root
    

If you are using Ubuntu 18.04 in WSL, the command has changed to ubuntu1804 , so

ubuntu1804 config --default-user root
  • Now Bash on Ubuntu on Windows logs you in as root without asking password
  • Use passwd command in Bash to change the user password (the user whose password you want to reset):

    passwd your_username
    
  • Change the default user back to your normal user in Windows command prompt

    ubuntu config --default-user  your_username
    

If you are using Ubuntu 18.04 in WSL, the command has changed to ubuntu1804 , so

ubuntu1804 config --default-user your_username

Watch Full Video to Recover your password Windows Subsystem Linux https://youtu.be/dTR232yvDCE

Note 1: The subsystem used in the video is not Ubuntu, but Kali Linux. Hence the difference in the command.

Note 2: If you are still using the original Ubuntu subsystem that came with the Anniversary Update, use the command lxrun. Upgrade to the subsystem version distributed via Microsoft Store is recommended.)

Solution 2:

Microsoft has a good help page on this: WSL User documentation.

In Windows PowerShell (Super+X, i) you can log in to the Ubuntu root account with

wsl --user root

Then change the password as you usually would, i.e. for the current user (which is root) with

passwd

or for another user with

passwd username

which interactively asks you for a new password (twice). Windows admin privileges are not required.

If you have more than one distribution installed in WSL, then you can list the names of the installed distributions with

wsl -l

and then use the name of the distribution to specify into which distribution you want to log in to, for example to log into Ubuntu 20.04:

wsl -d Ubuntu-20.04 --user root

Solution 3:

The above did not work. Even after changing default user, Bash always opened with my user.

So instead I did this, which worked:

  1. Edit this file (in notepad or notepad++):

    %localappdata%\lxss\rootfs\etc\shadow
    
  2. Find your normal user, for example:

    user1:$jsdjksadgfhsdf.saflsdf.sadf.safd:17299:0:99999:7:::
    

    and simply remove the hash part (below part)

    $jsdjksadgfhsdf.saflsdf.sadf.safd
    

    you will see a different hash - I hope :) so it should look like:

    user1::17299:0:99999:7:::
    
  3. Save the file

  4. Start Bash again with root privileges and set your password

     sudo bash
     passwd <your-user-name> 
    

    You can now set a new password without having to enter the previous one.