Windows wsl root password

How to set the `WSL` password from Windows 10?

Scenario

After automatically installing a fresh installation of Windows Subsystems for Linux Ubuntu 16.04 with commands:

a new installation is installed with username: exampleUsername . Next, if one wants to execute a command with sudo priviliges, e.g. yes | sudo apt update , one is prompted for the password of exampleUsername twice.

Question

How can I set that user password from Windows 10 using a script has the password?

Attempts

  1. Create a password changing powershell .ps1 file with content:

But that returns still a manual prompt for the password when it’s executed:

PS C:\twInstall> ./pw.ps1 Changing password for exampleUser. (current) UNIX password:

  1. Tried piping the password twice to the passwd command with pw.ps1 content:

which returns error:

passwd : The term ‘passwd’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\twInstall\pw.ps1:1 char:25 + wsl testtest testtest | passwd +

+ CategoryInfo : ObjectNotFound: (passwd:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Comment feedback adaptation

Currently, the scripts are run on a on a Windows 10 Pro N 64 bit (desktop), version 1709, build 16299.192 with WSL Ubuntu 16.04.2 LTS .

  1. Based on the answer suggested by @harrymc: 3.1 First set the default user to root with command:

3.2 Then create another the user (by setting it to default user) with command:

3.3 run a command as that user just incase anything needs to be initialised in the wsl for the creation of the user:

Читайте также:  Steam для windows 10 не работает

3.4 Switch back to root user with command:

3.5 Then set the path to the passwd file (manual inspection found it at: /etc/passwd hence:

3.6 Then change the password for the non-root user with command:

‘chpasswd’ is not recognized as an internal or external command, operable program or batch file.

3.7 Retrying with sudo yielded the same error:

‘chpasswd’ is not recognized as an internal or external command, operable program or batch file.

3.8 Since concerns were raised whether wsl Ubuntu 16.04.2 LTS had the capability of chpassword, I tried it afterwards in the wsl manually which did not throw any errors with command:

3.9 Apparently there occurs an error in the conversion from:

I am suspecting it is due to errors in how piping works when you run a wsl command from cmd or powershell.

Reset Password for WSL Linux Distro in Windows 10

If you forgot the password for your user account in a WSL Linux distro, and are unable to log in to its console, then this article will definitely be useful for you. We will see how to reset the account password in WSL Linux without using third party tools.

The ability to run Linux natively in Windows 10 is provided by the WSL feature. WSL stands for Windows Subsystem for Linux, which initially, was limited to Ubuntu only. Modern versions of WSL allow installing and running multiple Linux distros from Microsoft Store.

After enabling WSL, you can install various Linux versions from the Store. You can use the following links:

When you start a WSL distro for the first time, it opens a console window with a progress bar. After a moment of waiting, you will be prompted to type a new user account name, and its password. This account will be your default WSL user account that will be used to sign-in automatically every time you run the current distro. Also, it will be included in the ‘sudo’ group in order to allow it to run commands elevated (as root).

Читайте также:  Что делать если сломался windows

Each Linux distribution running on the Windows Subsystem for Linux has its own Linux user accounts and passwords. You will have to configure a Linux user account any time you add a distribution, reinstall, or reset. Linux user accounts are not only independent per distribution, they are also independent from your Windows user account.

To Reset the Password for a WSL Linux Distro in Windows 10,

  1. Change the default user name for your WSL distro to root. Use the following command: ubuntu config —default-user root . For other distros, see Note below.
  2. Launch your Linux distribution, e.g. type ubuntu , or wsl if you are working with your default WSL distro.
  3. Reset your password using the passwd command: passwd . Substitute the portion with the actual user name you want to reset the password for, e.g. #passwd winaero .
  4. Leave your WSL session and set the default user of the WSL distro back to your user account, e.g. ubuntu config —default-user winaero .

Note: Use the following commands to change your default user to root in a WSL distro. By replacing ‘root’ with another user account name, you’ll set it as your default user account for the distro.

  • 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

Articles of interest:

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

Share this post

About Sergey Tkachenko

Sergey Tkachenko is a software developer from Russia who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

Читайте также:  Как сделать образ windows 2003

11 thoughts on “ Reset Password for WSL Linux Distro in Windows 10 ”

For some reason the commnad (ubuntu config –default-user root) was not working in my ubuntu wsl install.
So I opened a cmd prompt and ran wsl -u root this allowed me to run wsl as root in the cmd prompt.
Then at the root wsl prompt inside of the cmd prompt type the command to reset your account password (passwd ). You should then receive the same prompts to set a new password and confirm the new password.

Thanks to this comment I was able to change the pwd

Yes, I had the same issue and your workaround helped. Thank you!

in my Windows environment needs to call ubuntu with the version ex:
ubuntu1804 config –default-user root
, the run
ubuntu1804

Thank you very much

Thank u very much 🙂

type ubuntu and tab. On mine it showed the executable name was actually called ubuntu1804.exe

Thank you so much, this was helpful.

Very helpful thank you so much

But, when setting the root as a default user, we need to enter the full version of Ubuntu. For example:

CLI:
Ubuntu2004 config –default-user root

In this case the version of ubuntu is 20.40

A continuation of @Esam Alaslmy’s answer:

To find out the name of the command, go to:

In my case I see the file: ubuntu1804.exe

To get the command you just drop the “.exe”. So for me the command is:

Please note: there are two hyphens in front of “default”

Оцените статью