I have installed Linux Bash on Windows 10 (available from Microsoft), but I've forgotten my password.
I've searched for a solution but I only find suggestions that involve doing something before the system boots, like accessing recovery mode, but that will not work in this case as this Ubuntu is just an application within a Windows system and doesn't have its own boot process.
How can I reset my password?
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?In Windows admin command prompt (Super+X, A) change the default user to root:
If you are using Ubuntu 18.04 in WSL, the command has changed to
ubuntu1804
, soUse
passwd
command in Bash to change the user password (the user whose password you want to reset):Change the default user back to your normal user in Windows command prompt
If you are using Ubuntu 18.04 in WSL, the command has changed to
ubuntu1804
, soWatch 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.)
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
Then change the password as you usually would, i.e. for the current user (which is root) with
or for another user with
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
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:
The above did not work. Even after changing default user, Bash always opened with my user.
So instead I did this, which worked:
Edit this file (in notepad or notepad++):
Find your normal user, for example:
and simply remove the hash part (below part)
you will see a different hash - I hope :) so it should look like:
Save the file
Start Bash again with root privileges and set your password
You can now set a new password without having to enter the previous one.
Edit This no longer works if you have a store-installed distribution of WSL.
To add to Tmu's answer, here's a Powershell script (gist) that automates the process (including automatically detecting the current default username)
I needed to reset my password also in my Windows 10, I has WLS 1
1- Check your linux/ubuntu name, listing the folder:
In my case I found Ubuntu1604.exe, so I will use ubuntu1604 like name for the next step.
2- Open CMD with administrator privilegies and run (you will get nothing in return):
3- Start your WSL, check that you get root privilegues or run whoami (you need to be root) and change your password with:
4- Close your WSL and get back to the CMD Window and set back your default linux username:
5- Start your WSL/Ubuntu/AnotherLinux again, check and enjoy.
For those of you who lost the root password, what worked for me, was updating to Ubuntu 18.04 LTS via the Windows Store. Note, the windows store has two distinct options:
To check your current version, run the following as any user:
At command prompt, enter:
You should see a line in the output that says:
If you see that, then definitely update to 18.04, and it will prompt you to create new UNIX credentials.