I've had to do this three times now, so I finally wrote it down. If you use WSL inside VS Code and keep forgetting your Linux password (it happens!), this is your go-to reference.
The Problem
WSL (Windows Subsystem for Linux) has its own separate password from your Windows login. If you rarely run sudo commands, it's easy to forget, and when you need it (like installing a Python package), you're stuck.
Here's how to reset it in under two minutes.
What You Need
- A Windows PC with WSL installed
- Access to Windows Command Prompt or PowerShell (not the WSL terminal)
- Your WSL distro name (e.g.
Ubuntu,Ubuntu-22.04)
Method 1: Reset via Root Login (Recommended)
Open a Windows Command Prompt or PowerShell, not your WSL terminal.
Step 1 — Find your distro name
wsl --list
Note the name shown (e.g. Ubuntu or Ubuntu-22.04).
Step 2 — Log in as root
wsl -d Ubuntu -u root
Replace
Ubuntuwith your actual distro name.
Step 3 — Reset your password
passwd your-username
Type your new password twice when prompted. You won't see characters as you type — that's normal.
Step 4 — Exit and verify
exit
Reopen your WSL terminal normally. You can now sudo with your new password.
Method 2: Change Default User to Root (If Method 1 Doesn't Work)
Run these in Windows PowerShell:
1. Set root as the default WSL user temporarily:
ubuntu config --default-user root
2. Open WSL, then reset your password:
passwd your-username
3. Restore your normal user as default (back in PowerShell):
ubuntu config --default-user your-username
How to Never Get Stuck Again
- Use a password manager —WSL credentials are separate from Windows, so store them in Bitwarden, 1Password, etc.
- Bookmark this article — seriously, just do it 😅
Tested on WSL 1 and WSL 2, Windows 10 and Windows 11.
Top comments (0)