Step-by-Step Guide to Resetting Your Ubuntu Username and Password on WSL

Step-by-Step Guide to Resetting Your Ubuntu Username and Password on WSL

1. Launch WSL as Root

Why?
Starting as the root user lets you modify any user’s settings without hassle.

How-to:

  • Open PowerShell or Command Prompt:
    Run:

      wsl -d Ubuntu -u root
    

    (Tip: Replace “Ubuntu” with your distro name if different.)

  • Reset your password:
    Inside the root shell, type:

      passwd your_username
    

    Replace your_username with your actual username. Enter your new password twice when prompted.

  • Check your users:
    Unsure of your username? Run:

      cat /etc/passwd | grep '/home'
    

    This lists users with home directories.

  • Exit and test:
    Type exit and then launch WSL normally to log in with your new password.


2. Change the Default User Temporarily

Why?
Switching the default user to root makes it easier to fix issues without manually launching as root every time.

How-to:

  • Set root as default:
    In PowerShell, run:

      ubuntu2004.exe config --default-user root
    

    (Adjust the command for your Ubuntu version.)

  • Launch WSL, reset the password:
    Use the same passwd your_username command as above.

  • Revert to your regular user:
    Once done, switch back:

      ubuntu2004.exe config --default-user your_username
    

3. Change Your Username

Warning:
Editing system files is risky. Always back up important data first.

How-to:

  • Boot as root:
    Follow the steps in Method 1 to launch as root.

  • Edit /etc/passwd:
    Open the file with a text editor:

      nano /etc/passwd
    

    Find the line with your current username:

      old_username:x:1000:1000:Your Name,,,:/home/old_username:/bin/bash
    

    Replace old_username with new_username and update the home directory path if needed.

  • Rename the home directory:
    Run:

      mv /home/old_username /home/new_username
    
  • Set a new password:
    Finally, update your password:

      passwd new_username
    

4. Reinstall Your Ubuntu WSL (Last Resort)

Why?
If nothing works, starting fresh might be the simplest solution.

How-to:

  • Backup your data:
    Move any important files from WSL to your Windows system.

  • Unregister your distro:
    In PowerShell:

      wsl --unregister Ubuntu
    
  • Reinstall from the Microsoft Store:
    Download Ubuntu again and set up your new username and password during initial configuration.


Wrapping Up

No matter which method you choose, regaining access to your WSL Ubuntu setup is easier than you think. These steps let you adjust your credentials quickly—so you can get back to coding without missing a beat.

Have questions or tips of your own? Drop a comment below, and let’s keep the conversation going!