Change your WSL username from the command line

To change your username in Windows Subsystem for Linux, you use the usermod command while logged in as root or with sudo privileges. The process takes about two minutes and does not require restarting WSL, though you will need to log out and back in to see the change take effect.

Open PowerShell or Command Prompt on your Windows machine and type wsl to enter your Linux environment. Then run this command, replacing "oldusername" with your current username and "newusername" with what you want it to be:

sudo usermod -l newusername oldusername

If you also want to change your home directory name to match (so it becomes /home/newusername instead of /home/oldusername), add a second command right after:

sudo usermod -d /home/newusername -m oldusername

The -m flag tells usermod to move the contents of the old home directory to the new one automatically. Without it, your files stay in the old folder and you will have to move them by hand.

Key Takeaways

  • Use sudo usermod -l newusername oldusername to change just the username, keeping the home directory path the same.
  • Add sudo usermod -d /home/newusername -m oldusername on a second line to rename the home directory and move all your files at the same time.
  • Log out of WSL completely and log back in to see the new username take effect in your prompt and file listings.
  • If you get a "permission denied" error, make sure you are using sudo and that you are not currently logged in as the user you are trying to rename.

Why you cannot rename the user while logged in as that user

Linux does not allow you to rename a user account while you are actively using it. If you try to run usermod on your own username while logged in as yourself, you will get a "usermod: user oldusername is currently used by process" error or similar.

The fix is to switch to the root user first. Type sudo su and press Enter. You will now be running commands as root, which has permission to change any user account on the system, including the one you normally log in as. After you run the usermod commands, type exit to go back to your regular user account.

Changing your username if you set WSL to log in as root by default

Some WSL setups are configured to start with the root user instead of a regular user account. If that is your situation, you can change any username directly without needing sudo, because you are already running as root.

Type usermod -l newusername oldusername (without the sudo part) and then usermod -d /home/newusername -m oldusername to move the home directory. When you are done, type exit to return to the Windows command line.

What to do if the username change did not take effect

After you run the usermod commands, you must close WSL completely and open it again for the change to show up in your command prompt. straightforward typing exit once is not enough — you need to close the entire PowerShell or Command Prompt window that is running WSL.

Open a new PowerShell or Command Prompt window and type wsl again. Your prompt should now show the new username. If it still shows the old one, type whoami to see what username the system actually has you logged in as. If whoami shows the new name but your prompt does not, the prompt is just displaying a cached value and will update on its own after a few more logins.

Renaming the default user in your WSL distribution settings

WSL also stores a default username in its configuration file. If you want WSL to log you in as the new username automatically instead of asking you each time, you need to update this setting.

Open PowerShell as Administrator on Windows and run this command, replacing "DistroName" with the name of your Linux distribution (usually "Ubuntu" or "Debian"):

wsl -d DistroName -u newusername

This logs you into that distribution as the new user. To make it the default user that WSL starts with every time, run this command from PowerShell (not from inside WSL):

[wsl2-distro-name] config --default-user newusername

Replace [wsl2-distro-name] with your actual distribution name. After this, WSL will log in as your new username by default.

Fixing file permissions after a username change

If you moved your home directory using the -m flag, file ownership should update automatically. However, if you renamed the user without moving the directory, or if some files were created before the change, you may have files owned by the old username that the new username cannot edit.

To fix this, run sudo chown -R newusername:newusername /home/newusername to change ownership of all files in your home directory to the new username. The -R flag means "recursive," so it updates the directory and everything inside it.

Frequently Asked Questions

Can I change my WSL username without losing my files?

Yes. Using the -m flag with usermod moves your entire home directory and all its contents to the new location automatically. Your files stay exactly where they are, just under a new path.

What if I forgot my old username?

Type whoami inside WSL to see your current username. If you are logged in as root, type ls /home to see a list of all user directories on the system.

Do I need to change my username in Windows too?

No. Your Windows username and your WSL username are completely separate. Changing one does not affect the other. You can have a Windows username "Alice" and a WSL username "Bob" with no problems.

Will changing my username break any programs I have installed?

Most programs store their settings in your home directory and will work fine after a username change, especially if you used the -m flag to move the directory. Some older programs that hardcode paths might have issues, but this is rare in modern Linux software.

Can I rename multiple users at once?

No. You must run usermod once for each user you want to rename. Run the commands one at a time, making sure each one completes before moving to the next.