Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Reset WSL User Password (2 Ways)

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To reset a forgotten Linux user password in WSL, open PowerShell or Command Prompt as Administrator and run wsl -u root to enter the distro as root, then use the passwd command to set a new password. This works for the default WSL distro and only takes a few minutes.

What You'll Need

  • Windows 10 or 11 with WSL installed (any version).
  • Administrator access to Windows (to run the command prompt as admin).
  • The name of your WSL distribution (e.g., Ubuntu, Debian, Kali). If you only have one distro, you can skip this.

Step-by-Step

  1. Open PowerShell or Command Prompt as Administrator. Press the Windows key, type "PowerShell" or "cmd", right-click the result, and select "Run as administrator". Accept the UAC prompt if it appears.
  2. Check your WSL distribution name (optional). Run wsl --list to see all installed distros. Note the exact name (e.g., "Ubuntu-22.04"). If you only have one, you can skip this.
  3. Start WSL with root access. In the same admin window, type wsl -u root and press Enter. If you have multiple distros and want to reset a specific one, use wsl -d -u root (replace <DistroName> with the actual name). This opens a shell inside the Linux environment as the root user.
  4. Reset the password. At the Linux prompt (which should show something like root@machine:/#), type passwd username and press Enter. Replace username with the actual username of the account you want to reset (e.g., passwd john). If you don't know the username, you can list all users by running cat /etc/passwd and looking for entries before the colon (e.g., "john:x:1000:...").
  5. Enter a new password. You will be prompted to type the new password, then retype it to confirm. Note that the password is not shown as you type (no asterisks), so type carefully and press Enter after each prompt.
  6. Exit the root shell. Type exit and press Enter to return to Windows. You can now close the admin window.
  7. Test the new password. Open a normal WSL terminal (e.g., by typing wsl in a regular PowerShell or Command Prompt), and log in with the new password when prompted. If you normally log in automatically (no password prompt), you can test by running sudo and entering the new password.

Common Mistakes

  • Not running as Administrator: If you don't run the command prompt as admin, you may get an error like "Access is denied" or "The requested operation requires elevation". Always right-click and select "Run as administrator".
  • Using the wrong distribution name: If you have multiple distros and use wsl -u root without specifying the distro, it may open the default one, not the one you want. Always check with wsl --list and use -d if needed.
  • Typing the password with visible characters: The terminal does not show any feedback when typing the password. Some users think the keyboard is broken, but it's normal. Type blindly and press Enter.
  • Forgetting to replace 'username': Running passwd without a username resets the password for the current user (root). If you want to reset another user, you must specify the username.

Tips

  • Use a strong password: Choose a mix of letters, numbers, and symbols. Avoid using the same password as your Windows login.
  • Write it down temporarily: If you tend to forget, store the new password in a password manager immediately after setting it.
  • Set up passwordless sudo (optional): If you find yourself constantly typing the password, you can configure NOPASSWD in the sudoers file, but that reduces security. Only do this on a personal machine.
  • Back up important data: While resetting the password doesn't delete files, it's always good to have a backup of critical data in case of other issues.

Troubleshooting

If you get "The term 'wsl' is not recognized": This means WSL is not installed. Install it by running wsl --install in an admin PowerShell, then reboot and set up a distro.

If you get "There is no distribution installed": You have WSL but no Linux distro. Install one by running wsl --install -d Ubuntu (or your preferred distro) from an admin prompt.

If the password change fails with "passwd: Authentication token manipulation error": This can happen if the filesystem is mounted read-only or if the user's account is locked. Try running mount -o remount,rw / as root first, then retry the passwd command.

If you can't log in after resetting: Double-check that you used the correct username. If you reset the password for the wrong user, simply repeat the steps with the correct username.

If the root shell doesn't open: Make sure you're using the exact distribution name. For example, if your distro is named "Ubuntu-22.04", use wsl -d Ubuntu-22.04 -u root. You can find the exact name with wsl --list.

If you have WSL 1 and the steps don't work: WSL 1 also supports wsl -u root. If it fails, try running wsl --shutdown first, then retry.

Frequently Asked Questions

Can I reset the password without knowing the username?

Yes. As root, you can list all users by running cat /etc/passwd. Look for lines like username:x:1000:... – the part before the first colon is the username.

Will this delete my files or installed programs?

No. Resetting the password only changes the password hash. Your files, home directory, and installed packages remain untouched.

What if I have multiple WSL distros?

Use the -d flag to specify which one, e.g., wsl -d Ubuntu-22.04 -u root. If you don't specify, it uses the default distro.

Can I reset the Windows user's password this way?

No. This only resets the Linux user password inside WSL. To reset a Windows account password, you need Windows recovery options or a Microsoft account reset.

Do I need to be an administrator on Windows?

Yes, because running wsl -u root requires elevation. Without admin rights, the command fails.

What if I set a new password but the old one still works?

That's unlikely. If you still see the old password accepted, you may have reset the password for a different user. Check the username again and repeat the steps.