The usermod command is the standard way to change your Linux username
To change your username on Linux, you use the usermod command in the terminal. The command itself is straightforward — usermod -l newusername oldusername — but there are several things you need to know before you run it. You must be logged in as root or use sudo, you cannot change the username of an account you are currently logged into, and changing your username does not automatically rename your home directory.
The reason for these restrictions is that your username appears in file permissions, running processes, and system logs. If you change it while logged in, the system becomes confused about who owns what. If you change it without also renaming your home directory, you end up with a folder called /home/oldusername that belongs to a user with a new name, which breaks things like your shell configuration files.
The full process takes about five minutes and involves three steps: switching to a different user account, running usermod to change the name, and renaming your home directory. This guide walks through each one in order.
Key Takeaways
- You cannot change your own username while logged in — you must switch to a different account or use root access first.
- The usermod command changes your username in the system, but does not rename your home directory automatically.
- You must rename your home directory separately, or your new username will point to a folder with your old name in it.
- After you change your username and home directory, log out completely and log back in to confirm the change took effect.
Log in as root or switch to a different user account
Open a terminal and switch to the root user by typing su - and entering the root password. If your system uses sudo (most modern Linux distributions do), type sudo -i instead and enter your own password. Either command gives you root access, which you need to run usermod.
If you want to avoid using root, you can instead log out of your current account and log in as a different user — one that has sudo permissions. Open a new terminal window, press Ctrl+Alt+F2 to switch to a text login screen, and log in with a different username. This is safer than using root if you are not comfortable with it, because you can only change one account at a time and you cannot accidentally damage the system while logged in as a regular user.
Run usermod to change the username
Type the usermod command with the -l flag (the letter L, not the number 1), followed by the new username, then the old username:
usermod -l newusername oldusername
Replace newusername with what you want to be called and oldusername with your current username. For example, if your username is james and you want to change it to jim, type usermod -l jim james. Press Enter and wait for the command to finish — if it succeeds, you will see no message at all, which is normal.
If you see an error like "user is currently logged in", you did not fully switch away from your original account. Go back to the previous step and make sure you are logged in as root or a different user. If you see "user does not exist", check that you spelled the old username correctly by typing id to see your current username.
Rename your home directory
Your home directory is still named after your old username. You must rename it so it matches your new username. Type:
usermod -d /home/newusername -m oldusername
This tells the system that the home directory for oldusername is now /home/newusername, and the -m flag tells it to move all the files there. Replace newusername and oldusername with the same names you used in the previous step. If your old username was james and your new one is jim, type usermod -d /home/jim -m james.
Again, you will see no message if it succeeds. If you see "user does not exist", the previous usermod command did not work — go back and check for typos.
Log out and log back in to confirm the change
Exit the root or alternate user account by typing exit. Then log out completely — if you are using a graphical desktop, click the power icon and select Log Out. If you are in a text terminal, press Ctrl+D or type logout.
Log back in with your new username. If the login works and you see your files in your home directory, the change was successful. You can verify by opening a terminal and typing whoami, which will print your current username.
What to do if something went wrong
If you cannot log in with your new username, log in as root or a different user and check what happened. Type id newusername to see if the account exists. If it does not, the usermod command failed — try running it again, checking carefully for typos.
If the account exists but you cannot log in, the home directory may not have the right permissions. Type ls -ld /home/newusername to see who owns it. It should show your new username as the owner. If it shows your old username, run the usermod command again with the -m flag. If permissions look correct but login still fails, try logging in as root and running passwd newusername to reset the password.
Changing the username of another user account
The same process works for changing someone else's username, but you must be logged in as root. You do not need to switch away from their account because you are not logged in as them. straightforward run the usermod commands as described above, using their old username and the new username you want to give them.
If the other user is currently logged in, they will not see the change until they log out and log back in. Their running processes will still show the old username until they restart. This does not cause problems — the system keeps track of user IDs, not usernames, so permissions and file ownership continue to work correctly even if the name changes while they are logged in.
Frequently Asked Questions
Can I change my username without using the terminal?
Most graphical Linux desktops have a Settings or Users panel where you can change your username, but it does the same thing as usermod behind the scenes. The terminal method gives you more control and shows you exactly what is happening. If your desktop has a user settings panel, you can use that instead — it will handle the home directory rename automatically.
What if I want to keep my old home directory name?
You can change your username without renaming the home directory by running only the first usermod command, without the -d and -m flags. Your home directory will still be called /home/oldusername even though your username is new. This works, but it can be confusing — most people rename the directory to match.
Will changing my username affect my files or permissions?
No. Linux tracks file ownership by user ID, not by username. When you change your username, your user ID stays the same, so all your files continue to belong to you. The username is just a label the system uses to display who owns something — changing the label does not change the ownership itself.
Can I change my username if I forgot the root password?
If you have sudo permissions, you can use sudo usermod instead of logging in as root. If you do not have sudo permissions and do not know the root password, you cannot change your username from the running system. You would need to boot into recovery mode or use a live USB, which is beyond the scope of this guide.
What if the usermod command says "user is currently used by some process"?
This means a program or service is running under your old username. Close all applications and log out completely, then try again. If you are changing someone else's account, make sure they are fully logged out — check with w or who to see all logged-in users.