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 requires you to open PowerShell or Command Prompt on your Windows machine, then run a few commands in your WSL terminal.
The most direct method is to rename your existing user account without creating a new one. This keeps your home directory, files, and permissions intact. You do not need to reinstall WSL or lose any of your work.
Before you start, know your current username and decide on the new one. Usernames in Linux are lowercase, typically contain only letters and numbers, and cannot start with a number. Hyphens and underscores are allowed but spaces are not.
Key Takeaways
- You must run commands as root or with sudo to change your username, which means using sudo usermod -l or logging in as the root user first.
- Changing the username does not affect your home directory or files — they stay where they are, but the folder name may not update automatically.
- If you cannot log in as root because you do not know the password, you can reset it from PowerShell using wsl --user root.
- After changing your username, you may need to update your WSL default user in Windows settings so you log in with the new name automatically.
Log in as root to change the username
The easiest way to change your username is to log in as the root user, then run the rename command. Open PowerShell on Windows and type wsl --user root. This logs you into your WSL distribution as root without needing a password.
Once you are at the root prompt (you will see a # instead of a $), type the usermod command. Replace oldusername with your current username and newusername with what you want it to be:
usermod -l newusername oldusername
Press Enter. The command runs silently — if you see no error message, the change worked. Type exit to log out of the root session and return to Windows.
Update your home directory name (optional)
When you change your username with usermod, your home directory keeps its old name. For example, if your old username was alex and you change it to jordan, your home folder is still /home/alex instead of /home/jordan. This does not break anything, but it can be confusing.
To rename the home directory itself, log in as root again and use the mv command:
mv /home/oldusername /home/newusername
Then update the home directory path in the user's account record by running:
usermod -d /home/newusername -m newusername
The -m flag tells usermod to move the contents of the old directory to the new one. After this, everything points to the correct location.
Set your new username as the default WSL user
When you start WSL from PowerShell or Windows Terminal, it logs you in as a specific default user. If you changed your username, you may need to update this setting so WSL knows to log you in as your new username automatically.
Open PowerShell and run:
wsl --user newusername
This logs you in with your new username to confirm it works. If you want to make this the default every time you open WSL, you can set it in Windows Terminal settings. Open Windows Terminal, go to Settings, find your WSL distribution in the left sidebar, and look for the "Default profile" or "Command line" option. Some versions of Windows Terminal let you set the default user directly; others require you to edit the settings.json file and add "defaultProfile": "newusername" to your distribution's configuration.
Reset your root password if you are locked out
If you do not know the root password and cannot log in as root, you can reset it from PowerShell without losing your WSL installation. Open PowerShell and run:
wsl --user root
This logs you in as root with no password required. Once you are at the root prompt, set a new root password by typing:
passwd
You will be asked to enter a new password twice. After that, you can use this password to log in as root in the future, or you can use sudo commands with your regular user account if you set up sudo access.
Use sudo if you prefer not to log in as root
If your user account has sudo privileges, you can change your username without logging in as root. Open your WSL terminal and run:
sudo usermod -l newusername oldusername
You will be prompted for your password. Enter it, and the command runs with elevated privileges. This method works the same way as logging in as root, but you stay in your regular user session.
To rename your home directory with sudo, run:
sudo mv /home/oldusername /home/newusername
sudo usermod -d /home/newusername -m newusername
If your user account does not have sudo access, you will see a message saying you are not in the sudoers file. In that case, log in as root using the method described above.
Verify the change worked
After you change your username, check that everything is correct by logging out and back in. Exit your current WSL session by typing exit, then open a new WSL terminal from PowerShell or Windows Terminal.
At the prompt, type whoami. This command prints your current username. If it shows your new username, the change was successful. You can also type pwd to see your current working directory and confirm it points to the right home folder.
If you see your old username, the change did not take effect. Log in as root again and check that the usermod command ran without errors. Common mistakes include typos in the old or new username, or trying to change to a username that already exists on the system.
Frequently Asked Questions
Will changing my username delete my files?
No. Your files stay in place regardless of what your username is. The usermod command only changes the name associated with your user account. If you also rename your home directory, your files move with it, but nothing is deleted.
Can I change my username if I am not the administrator on Windows?
Yes. Your Windows administrator status does not affect WSL. You can change your WSL username as long as you can open WSL and log in as root or have sudo privileges. WSL runs independently of Windows user accounts.
What if I want to create a new user instead of renaming the old one?
You can create a separate user account with useradd -m newusername while logged in as root. This leaves your old account untouched. You would then need to set a password for the new user with passwd newusername and update your default WSL user in Windows settings.
Do I need to restart WSL after changing my username?
No restart is required. You can log out and log back in when ready. If you changed your default user in Windows Terminal settings, you may need to close and reopen Windows Terminal for the change to take effect.
What if the usermod command says the username is already in use?
This means another user account on your system already has that name. Choose a different username or remove the existing account first with userdel oldusername (as root). Be careful — this deletes the user account, though you can preserve the home directory by using userdel -r only if you want to remove everything.