Как сбросить пароль ubuntu в windows

WSL (Windows Subsystem for Linux) is a handy tool for people who want to enjoy the power of Linux command line from the comfort of Windows.

When you install Linux using WSL on Windows, you are asked to create a username and password. This user is automatically logged on when you start Linux on WSL.

Now, the problem is that if you haven’t used it for some time, you may forget the account password of WSL. And this will become a problem if you have to use a command with sudo because here you’ll need to enter the password.

reset wsl password

Don’t worry. You can easily reset it.

Reset forgotten password for Ubuntu or any other Linux distribution on WSL

To reset the Linux password in WSL, you have to:

  • Switch the default user to root
  • Reset the password for the normal user
  • Switch back the default user to the normal user

Let me show you the steps in detail and with screenshots. If you want a video, you can watch that as well.

Step 1: Switch to root as default user

It will be wise to note down your account’s normal/regular username. As you can see, my regular account’s username is abhishek.

username wsl

Note down the account username

The root user in WSL is unlocked and doesn’t have a password set. This means that you can switch to the root user and then use the power of root to reset the password.

Since you don’t remember the account password, switching to the root user is done by changing the configuration of your Linux WSL application and make it use root user by default.

This is done through Windows Command Prompt and you’ll need to know which command you need to run for your Linux distribution.

This information is usually provided in the description of the distribution app in the Windows Store. This is from where you had downloaded your distribution in the first place.

wsl distro command

Know the command to run for your distribution app

From the Windows menu, start the command prompt:

Start Command Prompt in windows

Start Command Prompt

In here, use your distribution’s command in this fashion. If you were using the Ubuntu app from Windows store, the command would be:

ubuntu config --default-user root

In the screenshot, I am using Ubuntu 20.04 app from the Windows store. So, I have used ubuntu2004 command.

wsl set root as default

Set root as default user in Linux app’s configuration

To save you the trouble, I am listing some distributions and their respective commands in this table:

Distribution App Windows Command
Ubuntu ubuntu config –default-user root
Ubuntu 20.04 ubuntu2004 config –default-user root
Ubuntu 18.04 ubuntu1804 config –default-user root
Debian debian config –default-user root
Kali Linux kali config –default-user root

Step 2: Reset the password for the account

Now, if you start the Linux distribution app, you should be logged in as root. You can reset the password for the normal user account.

Do you remember the username in WSL? If not, you can always check the contents of the /home directory. When you have the username, use this command:

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.

resetting wsl password

Reset the password for the regular user

Congratulations. The password for the user account has been reset. But you are done just yet. The default user is still root. You should change it back to your regular account user, otherwise, it will keep on logging in as the root user.

Step 3: Set regular user as default again

You’ll need the regular account username that you used with the passwd command in the previous step.

Start the Windows command prompt once again. Use your distribution’s command in the similar manner you did in step 1. However, this time, replace root with the regular user.

ubuntu config --default-user username

set regular user as default wsl

Set regular user as default user

Now when you start your Linux distribution app in WSL, you’ll be logged in as a regular user. You have reset the password fresh and can use it to run commands with sudo.

If you forgot the password again in the future, you know the steps to reset it.

If resetting WSL password is this easy, is this not a security risk?

Not really. You need physical access to the computer and access to the Windows account. If someone already has this much access, they can do much more than just change the Linux password in WSL.

Were you able to reset WSL password?

I gave you the commands and explained the steps. I hope this was helpful to you and you were able to reset the password of your Linux distribution in WSL.

If you are still facing issues or if you have a question on this topic, please feel free to ask in the comment section.

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?

Zanna's user avatar

Zanna

69.5k56 gold badges217 silver badges328 bronze badges

asked May 13, 2016 at 22:19

Maheedhar K V's user avatar

Maheedhar K VMaheedhar K V

3,4113 gold badges10 silver badges4 bronze badges

2

  • 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.)

Panther's user avatar

Panther

101k19 gold badges193 silver badges283 bronze badges

answered Aug 5, 2016 at 10:02

Tmu's user avatar

15

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

answered Sep 5, 2019 at 9:58

Nobody's user avatar

NobodyNobody

1,7991 gold badge10 silver badges15 bronze badges

10

Important This answer is (a) for the older WSL1 only, (b) is outdated as it references paths that are no longer used by WSL1, even, and (c) most importantly, can cause filesystem corruption, per Microsoft. Please refer to other answers here for proper methods of changing the password.

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:::
  1. Save the file

  2. 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.

NotTheDr01ds's user avatar

NotTheDr01ds

15.8k6 gold badges52 silver badges80 bronze badges

answered May 13, 2017 at 15:59

Vladimir Jirasek's user avatar

10

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)

# Resets the password for the default LXSS / WSL bash user
$lxssUsername = (Get-ItemProperty HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss).DefaultUsername
lxrun /setdefaultuser root
bash -c "passwd $lxssUsername"
lxrun /setdefaultuser $lxssUsername

answered Jun 6, 2017 at 23:52

Richard Szalay's user avatar

1

I needed to reset my password also in my Windows 10, I has WLS 1

1- Check your linux/ubuntu name, listing the folder:

%userprofile%\AppData\Local\Microsoft\WindowsApps

In my case I found Ubuntu1604.exe, so I will use ubuntu1604 like name for the next step.
 list files in: %userprofile%\AppData\Local\Microsoft\WindowsApps

2- Open CMD with administrator privilegies and run (you will get nothing in return):

ubuntu1604 config --default-user root

3- Start your WSL, check that you get root privilegues or run whoami (you need to be root) and change your password with:

passwd [your-linux-username]

4- Close your WSL and get back to the CMD Window and set back your default linux username:

ubuntu1604 config --default-user [your-linux-username]

5- Start your WSL/Ubuntu/AnotherLinux again, check and enjoy.

answered Oct 27, 2019 at 17:37

Jorgeee's user avatar

JorgeeeJorgeee

2834 silver badges10 bronze badges

The other answers here, while mostly valid, are vastly overcomplicated. To change your user password in any WSL distribution, simply:

From inside Ubuntu (or another distribution):

wsl.exe \~ -u root -d $WSL_DISTRO_NAME -e passwd $USER

*Requires WSL Interop to be enabled.

Or from PowerShell or CMD (as a regular, non-admin user):

wsl ~ -u root -e passwd <username>
# Add the -d <distro_name> if not using the default distro

*Does not require WSL Interop.

answered Dec 7, 2022 at 20:18

NotTheDr01ds's user avatar

NotTheDr01dsNotTheDr01ds

15.8k6 gold badges52 silver badges80 bronze badges

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:

  1. Ubuntu
  2. Ubuntu 18.04 LTS (Pick this one)

To check your current version, run the following as any user:

At command prompt, enter:

cat /etc/*release

You should see a line in the output that says:

DISTRIB_RELEASE=16.01

If you see that, then definitely update to 18.04, and it will prompt you to create new UNIX credentials.

answered Mar 15, 2019 at 1:24

Janac Meena's user avatar

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged

.

Asked

Viewed
21k times

I have Bash Ubuntu on Windows 10. This is enabled by turning on the Developer mode feature so the normal non-programmer would likely not need this. I need to reset the password. I must have typed it wrong (twice, somehow) when I first set it up. How can I do that?

  • windows
  • ubuntu
  • passwords

asked Oct 28, 2016 at 1:35

tom's user avatar

tomtom

1,3411 gold badge15 silver badges28 bronze badges

1 Answer

This has been answered HERE

Copying from their answer:

  1. In Windows command prompt change the default user to root:

    lxrun /setdefaultuser root

  2. Now Bash on Ubuntu on Windows logs you in as root without asking password

  3. Use passwd command in Bash to change the user password:

    passwd your_username

  4. Change the default user back to your normal user in Windows command prompt

    lxrun /setdefaultuser your_username

Community's user avatar

answered Oct 28, 2016 at 1:42

Everyone's user avatar

EveryoneEveryone

1,75114 silver badges36 bronze badges

3

  • That’s it! Thanks

    Oct 29, 2016 at 12:25

  • C:\Windows\system32>lxrun /setdefaultuser root Warning: lxrun.exe is only used to configure the legacy Windows Subsystem for Linux distribution. Distributions can be installed by visiting the Microsoft Store: aka.ms/wslstore Error: 0x80070002 New is: ubuntu1804, but I can’t figure out the commands

    Nov 19, 2018 at 13:16

  • @JaroslavŠtreit "%localappdata%\Microsoft\WindowsApps\ubuntu1804.exe" config --default-user root should do the trick

    Dec 11, 2018 at 16:37

  • The Overflow Blog
  • Featured on Meta

Related

Hot Network Questions

  • Electric Dryer Issue: Clothes Damp in Sensor Drying Mode

  • Is the Clebsch-Gordan decomposition of Lie algebra or Lie group representations?

  • Why do Atlas III and V use Russian RD-180 engines?

  • How to know the sample arithmetic mean and standard deviation if I know the mean and the deviation of the logarithm of the observations

  • How to stop Steam trying to read from a non-existent drive?

  • Copying files to directories according the file name

  • Redefining queue with different front and rear

  • Why did Vincent risk his chance of going to space by giving his true urine sample to Dr. Lamar in the last scene?

  • Students can’t seem to grasp the intent of tangent lines and getting general trends of derivatives from graphs

  • Schengen to Schengen with connecting flight via UK (non-Schengen)

  • What is the glyph origin of 規?

  • Exact positioning and how easy would it be to recreate this in LaTeX?

  • What could happen if my university loses its R2 status?

  • How to draw the trajectory of the circumscribed rectangle of an ellipse and determine the area range of the rectangle?

  • Why is the central truss segment of the ISS called S0?

  • How would a Bayesian define a fair coin?

  • Spacing on text macros

  • In the Spanish-American War (1898), who formally declared war first?

  • How can I tap a M5 hole in hardened steel bearing?

  • Can you identify this 6′ tall plant?

  • how i can filter persian alphabet in PHP for joomla 4

  • Business Schengen Visa for Tourism Purpose

  • Open pdf from a commadn line and go back to the command line

  • Difference between KDE, MLE and EM for density estimation

more hot questions

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

WSL

Jun 24, 2021

I recently wanted to install something within my Ubuntu shell and could not remember the password, and thought I was stuck. However, I found a way of resetting it quickly and easily.

  1. Open Bash on Ubuntu to take note of your Linux username (note that this may or may not match your Windows username)
  2. Close your bash session; you must do this for the following commands to work.
  3. Open a Windows command prompt as Admin
  4. Enter ubuntu config --default-user root to set the default user as root.

💡

If you find ubuntu is unrecognised as a command, try ubuntu2004 or swap the numbers to represent your version. 

5.   Now open your Ubuntu shell again.  This time you’ll notice you are logged in as root.

6.   You now want to change the password of your account type, passwd [username] and follow the instructions to reset your password.  Close the Ubuntu shell.

7.   Now, you want to change your Ubuntu shell to make your profile the default user.  Within a Windows command prompt, run the following command ubuntu config --default-user [username]

When you open your Ubuntu shell, your profile will defaultto yours, and the password will be reset.

Enjoy!

  • WSL
  • Windows 10
  • Tip
  • Troubleshooting

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Success!

Now check your inbox and click the link to confirm your subscription.

Please enter a valid email address

Oops! There was an error sending the email, please try later.

Recommended for you

Перейти к содержанию

На чтение 3 мин Просмотров 483 Опубликовано

Если вы забыли пароль своей учетной записи в дистрибутиве WSL Linux и не можете войти в его консоль, то эта статья определенно будет вам полезна. Мы увидим, как сбросить пароль учетной записи в WSL Linux без использования сторонних инструментов.

Возможность запускать Linux изначально в Windows 10 предоставляется функция WSL. WSL означает подсистему Windows для Linux, которая изначально была ограничена только Ubuntu. Современные версии WSL позволяют устанавливать и запускать несколько дистрибутивов Linux из Microsoft Store.

После включения WSL вы можете устанавливать различные версии Linux из Магазина. Вы можете использовать следующие ссылки:

  1. Ubuntu
  2. openSUSE Leap
  3. SUSE Linux Enterprise Server
  4. Kali Linux для WSL
  5. Debian GNU/Linux

и другие.

Когда вы впервые запускаете дистрибутив WSL, он открывает окно консоли с индикатором выполнения. Через некоторое время вам будет предложено ввести новое имя учетной записи пользователя и пароль. Эта учетная запись будет вашей учетной записью WSL по умолчанию, которая будет использоваться для автоматического входа при каждом запуске текущего дистрибутива. Кроме того, он будет включен в группу sudo, чтобы позволить ему запускать команды с повышенными привилегиями (как root).

Каждый дистрибутив Linux, работающий в подсистеме Windows для Linux, имеет своего собственного пользователя Linux. учетные записи и пароли. Вам придется настраивать учетную запись пользователя Linux каждый раз, когда вы добавляете дистрибутив, переустанавливаете или сбрасываете. Учетные записи пользователей Linux не только независимы для каждого дистрибутива, они также не зависят от вашей учетной записи пользователя Windows.

Чтобы сбросить пароль для WSL Linux Distro в Windows 10,

  1. Измените имя пользователя по умолчанию для вашего дистрибутива WSL на root. Используйте следующую команду: ubuntu config --default-user root . Для других дистрибутивов см. Примечание ниже.
  2. Запустите Linux распространение, например введите ubuntu или wsl , если вы работаете с дистрибутивом WSL по умолчанию.
  3. Сбросьте пароль с помощью команды passwd : passwd . Замените часть фактическим именем пользователя, для которого вы хотите сбросить пароль, например #passwd winaero .
  4. Выйдите из сеанса WSL и установите пользователь по умолчанию дистрибутива WSL обратно в свою учетную запись пользователя, например ubuntu config --default-user winaero .

Примечание. Используйте следующие команды, чтобы изменить своего пользователя по умолчанию на root в дистрибутиве WSL. Заменив ‘root’ другим имя учетной записи пользователя, вы установите ее в качестве учетной записи пользователя по умолчанию для дистрибутива.

  • Ubuntu: ubuntu config --default-user root
  • openSUSE Leap 42: openSUSE-42 config --default-user root
  • SUSE Linux: SLES-12 config --default-user root
  • Debian: debian config --default-user root
  • Kali Linux: kali config --default-user root

  • Как сбросить пароль postgres windows
  • Как сбросить пароль microsoft на windows 10
  • Как сбросить параметры экрана windows 10
  • Как сбросить параметры мыши на windows 10
  • Как сбросить параметры адаптера беспроводной сети на ноутбуке windows 7