9

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.

  • you are likely confused about the difference between sudo and su, see askubuntu.com/questions/70534/… – anx Jul 5 '17 at 6:35
  • well sudo -u root can be a desperate attempt to get things working. but sudo passwd should change the password. and old one should not be required when i open a new WSL shell and try 'sudo apt-get install' – Dragonborn Jul 5 '17 at 6:48
21
  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
  3. in wsl, passwd [user] will change the password of any WSL user
  4. in wsl, sudo generally asks for the password of the current WSL user.
  5. in windows cmd.exe, youn can change what user you will login into when opening WSL - if that user is root, you will be able to use option 3.
    • creators update and earlier: lxrun /setdefaultuser [user]
    • fall creators update and later: ubuntu.exe config --default-user [user]

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

  • yes am using a non-root as default user. this should work! thanks. – Dragonborn Jul 6 '17 at 7:24
  • lxrun /setdefaultuser no longer work :( – nowox Nov 9 '17 at 10:44
  • @nowox i have added the updated command to my answer. microsoft has updated their docs accordingly, you probably want to read the tutorial to understand how changing the default user can be (ab)used. – anx Nov 9 '17 at 15:45
  • lxrun /setdefaultuser [user] is working still in Windows 10, version 1709 (Fall Creators Update) – hrvoj3e Nov 26 '17 at 9:50
  • Note: You may have to restart your computer after changing the default user with ubuntu config --default-user [user]. I was really confused as to why it wasn't working. Once I restarted my computer, the default user was changed. – Alexander Aug 4 at 17:59
5

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.
  • /bin/bash/: config: command not found – systemovich Aug 8 at 10:34
  • @systemovich - you need to run the ubuntu config ... commands from a windows command prompt (cmd.exe). To open the bash shell from there, just type wsl and hit Enter. To return to the windows command prompt, from the WSL prompt, type exit and hit enter – StingyJack Sep 9 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.