The Two Ways to Change Your Linux Username
You can change your Linux username in two ways: rename your account while you are logged in as root or another administrator, or rename it while logged in as a different user. The first method is simpler if you have root access. The second is necessary if you are the only administrator on the machine. Both methods involve the same core command — usermod — but the setup differs.
Before you start, log out of the account you want to rename. You cannot change the username of an account you are currently using. If you are the only user on the machine, you will need to boot into single-user mode or use a live USB to access root, then make the change from there.
Key Takeaways
- You must be logged out of the account you want to rename, or logged in as root or another administrator account.
- The command to change a username is usermod -l newname oldname, where newname is what you want and oldname is the current username.
- Changing the username does not automatically change your home directory name — you must rename that separately with mv /home/oldname /home/newname.
- After renaming, check that file ownership is correct by running chown -R newname:newname /home/newname to may support the new user owns their home directory.
- If you are the only administrator, you may need to boot into single-user mode or use a live USB to make the change.
Changing Your Username When Logged In as Root
If you have root access or are logged in as a different administrator account, open a terminal and type the usermod command. Replace oldusername with the current username and newusername with what you want it to be:
sudo usermod -l newusername oldusername
Press Enter and type your password if prompted. The command runs silently — no message means it worked. To verify, type id oldusername and you should see an error saying the user does not exist. Then type id newusername and you should see the user ID and group information.
This command changes only the login name. Your home directory is still named after your old username, which can cause confusion. Most systems look for a home directory matching your username, so you should rename that too in the next section.
Renaming Your Home Directory
After changing the username, rename the home directory to match. Type:
sudo mv /home/oldusername /home/newusername
This moves the entire directory and everything in it to the new location. Verify it worked by typing ls /home and checking that the old directory name is gone and the new one is there.
Next, fix the file ownership so the new username owns the directory and all files inside it. Type:
sudo chown -R newusername:newusername /home/newusername
The -R flag means "recursive" — it changes ownership of the directory and everything inside. Without this step, files in your home directory may still be owned by the old username, which can cause permission problems later.
Changing Your Username When You Are the Only Administrator
If you are the only user with administrator privileges, you cannot run usermod while logged in as yourself. You must boot into single-user mode or use a live USB to access root without logging in as any regular user.
To boot into single-user mode on most Linux distributions, restart your computer and hold down Shift during startup to open the GRUB menu. Select the entry that says "recovery mode" or "single-user mode", then press Enter. The system will boot to a root prompt without asking for a password. From here, run the usermod and mv commands exactly as shown in the sections above.
If single-user mode is not available, read a live USB image of your Linux distribution, write it to a USB drive using a tool like Balena Etcher or Rufus, and boot from the USB. Once the live system is running, open a terminal and run the same commands. The live system has root access and can see your hard drive.
Fixing Problems After a Username Change
If you renamed your username but forgot to rename your home directory, or if you renamed the directory but did not fix ownership, you may see permission errors when you log in. The most common sign is that you cannot write files to your home directory or that graphical programs fail to start.
To fix this, log in as root or another administrator and run both commands again: first the mv command to rename the directory if needed, then the chown command to fix ownership. If the directory is already named correctly, just run the chown command alone.
If you see errors about a missing .Xauthority file or similar, these are usually created automatically the next time you log in. Log out and back in, and they should reappear. If they do not, you can create an empty one by typing touch /home/newusername/.Xauthority while logged in as root.
Changing Your Username Without Renaming the Home Directory
In some setups, you may want to change the login username but keep the home directory name the same. This is less common but possible. After running usermod, you need to tell the system where the new username's home directory is located.
Type:
sudo usermod -d /home/olddirectoryname newusername
This tells the system that the user newusername has a home directory at /home/olddirectoryname. When you log in with the new username, the system will use that directory as your home. This approach works but can be confusing — most people rename both the username and the directory to match.
Frequently Asked Questions
What happens to my files when I change my username?
Your files stay in place. Changing the username does not delete or move anything. However, if you do not rename your home directory and fix ownership, the system may not let you access your files properly. Always run the mv and chown commands after changing the username.
Can I change my username while I am logged in?
No. You must log out first, or log in as a different administrator account. If you try to change the username of the account you are currently using, the command will fail or cause problems. Always switch users or log out before making the change.
Do I need to change anything else after renaming my username?
Most things work automatically after you rename the username and home directory. However, if you have cron jobs, scheduled tasks, or configuration files that reference your old username, you may need to update those manually. Check files in /etc/cron.d and your process settings if something stops working.
What if I do not have root access and I am the only user?
You will need to boot into single-user mode or use a live USB. Single-user mode is faster if your system supports it — hold Shift during startup and select recovery mode. If that does not work, create a live USB and boot from it to gain root access.
Can I change my username back to the old one?
Yes. Run the same usermod command with the names reversed: sudo usermod -l oldusername newusername. Then rename the home directory back with sudo mv /home/newusername /home/oldusername and fix ownership again with chown. The process is identical.