135

I have tried both commands

sudo passwd

and

sudo -u root /bin/bash

But as soon as I enter the new password twice, it says password has been updated. You close the shell and open a new instance, it is still working on the old root password.

Please help.

Dragonborn
  • 1,453

5 Answers5

306

There is a simpler method.

  1. Open Windows terminal cmd.exe
  2. Type wsl -u root (optional -d <distro-name>)
  3. Type passwd username and change the password
  4. Type exit
  5. Type wsl (optional -d <distro-name>)
  6. Type sudo echo hi to confirm the new root password works.
bicole
  • 3,541
65
  1. in wsl, sudo passwd will change the password of the WSL root user.
  2. in wsl, passwd will change the password of the current WSL user
  • to specify which WSL user to use (temporarily) wsl -u [user]
  1. in wsl, passwd [user] will change the password of any WSL user
  2. in wsl, sudo generally asks for the password of the current WSL user.
  3. in windows cmd.exe, you can change the default WSL user (permanently):
  • in current versions: ubuntu.exe config --default-user [user]
  • in legacy versions 1703, 1709: lxrun /setdefaultuser [user]
  • a restart may be required

You probably want to change the password of the sudo-capable, non-root user.

You probably do not want to change the root users password (because in Ubuntu, the root user generally should not have a password, sudo should be used instead). You probably also do not want to leave your default user as root. Even when working form windows, its still a bad practice.

Official Microsoft documentation on User Accounts and Permissions can be found here: https://msdn.microsoft.com/en-us/commandline/wsl/user_support

anx
  • 2,457
  • 2
  • 26
  • 38
31

It is assumed you are using Ubuntu in this explanation.

  • If you forgot your password on WSL simply open your command prompt from windows by typing cmd on search.
  • Then type ubuntu config --default-user root to set root as the default user for Linux Bash Shell.
  • Then open the Linux Bash shell which will log you in as root without asking for password.
  • Then use passwd username to reset the password of any user.
  • Use ubuntu config --default-user username to reset back to your normal Linux user account.
abu_bua
  • 11,313
11

There is no need to reconfigure Ubuntu, but, if you have more than one distribution installed and Ubuntu is not your default, you must also specify the distribution in addition to the root user.

  • Option 1 -- Ubuntu is the default WSL distribution:

    wsl.exe -u root
    
  • Option 2 -- Ubuntu is not the default WSL distribution:

    1. First determine the distribution name:

      wsl.exe -l -v
      
    2. Then use the distribution name with -d/--distribution:

      wsl.exe -d <distro> -u root
      

Then go about your business to reset your regular user account. Stealing the one-liner from @NotTheDr01ds, assuming your distribution name is "Ubuntu":

wsl.exe -d Ubuntu -u root passwd username

Typical Ubuntu distribution names include:

  • Ubuntu: When installed from the Microsoft Store or wsl --install as the "unversioned" app.
  • Ubuntu-18.04, Ubuntu-20.04, or Ubuntu-22.04: When installed from the Microsoft Store or wsl --install as a specific version of Ubuntu.
NotTheDr01ds
  • 22,082
John T.
  • 211
1

1.Open command prompt (as administrator) in windows 2.Type Ubuntu2004 config --default-user root 3.Start linux app (Ubuntu 20.04.6 LTS) 4.type 'passwd [user]' and change password for user.

syam218
  • 11