The two ways to change your Linux username
You can change your username in Linux using the command line, and the method depends on whether you are logged in as the user whose name you want to change. The most straightforward approach is to use the usermod command if you have administrator (root) access, or to use passwd and related tools if you are changing your own account. Both methods change the username in the system files that track user accounts, but they work differently depending on your situation.
Before you start, log in as root or use sudo to run commands with administrator privileges. If you are changing another user's name, that user must not be logged in — Linux will not let you rename an active account. If you are changing your own username, you will need to log out first, then log back in as root or another administrator account to make the change.
Key Takeaways
- The usermod -l command changes your username in the system files, but you must run it as root and the user account must be logged out.
- You may also need to rename your home directory from /home/oldname to /home/newname using the mv command, and update the home directory path in the user record with usermod -d.
- Changing your username does not affect files you own — they stay yours — but the owner name displayed in file listings will show the new username once the system cache refreshes.
- If you use sudo without a password or have sudo rules tied to your old username, you will need to update your sudo configuration in /etc/sudoers after the change.
Using usermod to change the username
The usermod command is the standard tool for modifying user account details. To change a username, open a terminal and log in as root, or use sudo to run the command with administrator privileges. The syntax is straightforward: sudo usermod -l newusername oldusername. The -l flag stands for "login" and tells usermod to change the login name.
For example, if your old username is john and you want to change it to jonathan, you would type:
sudo usermod -l jonathan john
This command updates the username in /etc/passwd, the file where Linux stores user account information. The change takes effect when ready, but you will not see it reflected in your terminal prompt until you log out and log back in. If you are changing your own username, you must log out completely, then log back in as root or another administrator to run the command.
Renaming your home directory
Changing the username alone does not automatically rename your home directory. Your home folder will still be located at /home/oldusername even after you change your login name. To keep things organized and avoid confusion, you should rename the directory to match your new username.
Use the mv command to rename the directory:
sudo mv /home/oldusername /home/newusername
After moving the directory, you must update the user record to point to the new location. Use usermod again with the -d flag to set the home directory path:
sudo usermod -d /home/newusername newusername
If you skip this step, your home directory path in the system files will still point to the old location, which can cause problems when you log in. The system may not find your configuration files or may create a new home directory in the wrong place.
Updating sudo permissions if needed
If you have custom sudo rules or passwordless sudo access tied to your old username, you will need to update them after the change. These rules are stored in /etc/sudoers, a file that controls who can run administrator commands.
Never edit /etc/sudoers directly with a text editor. Instead, use the visudo command, which checks your syntax before saving and prevents you from locking yourself out:
sudo visudo
Look for any lines that mention your old username and replace them with your new one. For example, if the file contains john ALL=(ALL) NOPASSWD: ALL, change it to jonathan ALL=(ALL) NOPASSWD: ALL. Save and exit (in the default editor, press Ctrl+X, then Y, then Enter). If you do not have custom sudo rules, you can skip this step.
What happens to your files and permissions
Changing your username does not change the ownership of files you created. Linux tracks file ownership by user ID (UID), a number assigned to each user account, not by the username itself. When you change your username, your UID stays the same, so all your files remain yours.
However, when you run ls -l to list files in a directory, the display shows the username associated with each file's UID. After you change your username, the system will display your new name next to your files. This is purely a display change — the underlying ownership has not moved.
If you have files outside your home directory that you own, they will also show your new username in file listings. There is no need to manually update permissions or ownership after a username change.
Checking that the change worked
After you have changed your username and renamed your home directory, verify that everything is correct. Log out completely and log back in with your new username. Open a terminal and type:
whoami
This command prints your current username. It should show your new name. Next, check that your home directory is correct by typing:
echo $HOME
This should print /home/newusername. If both commands show the correct values, your username change is complete. If echo $HOME still shows the old path, you may have missed the usermod -d step — go back and run it now.
Frequently Asked Questions
What if I forget to log out the user before changing their username?
Linux will not let you change a username while that user is logged in. The usermod command will return an error saying the user is currently in use. Log out the user completely, including any background processes or SSH sessions, and try again.
Can I change my own username while I am logged in?
No. You must log out first, then log in as root or another administrator account to run the usermod command. After the change is complete, you can log in with your new username.
Do I have to rename my home directory?
Technically no, but it is strongly recommended. If you leave your home directory at /home/oldusername, your system will still work, but it creates confusion and can cause problems with some applications that expect the home directory path to match the username.
Will changing my username affect my email or other accounts?
No. Your Linux username is separate from email accounts, online services, or other systems. Changing your Linux username only affects how you log into that specific computer. You will need to update passwords or usernames in other services separately if you want to.
What if I made a mistake and want to change it back?
You can change your username again using the same process. Run sudo usermod -l oldusername newusername, then rename your home directory back with sudo mv /home/newusername /home/oldusername, and update the home directory path with usermod -d again. Make sure you are logged in as root or another administrator.