The usermod command is the standard way to change your Ubuntu username
To change your username on Ubuntu, you use the usermod command with the -l flag (for "login"). The basic syntax is sudo usermod -l newusername oldusername. You must run this command as root or with sudo, and you cannot change the username of the account you are currently logged into — you need to be in a different user account or use a recovery mode.
Ubuntu stores usernames in the system files /etc/passwd and /etc/shadow. The usermod command updates these files safely without corrupting them. If you try to change your own username while logged in as that user, the system will refuse because the user account is in active use.
The process takes seconds once you have the right permissions and are logged into a different account. Most people do this from a second admin account or from recovery mode if they only have one account on the machine.
Key Takeaways
- You cannot change the username of the account you are currently logged into; you must switch to a different user account first or boot into recovery mode.
- The command is sudo usermod -l newusername oldusername, and it updates the system files that store your username.
- Your home directory name does not change automatically when you change your username, so you may want to rename it separately with sudo mv.
- If you have only one user account on the machine, create a temporary admin account or use recovery mode to make the change.
Step-by-step: changing your username from another account
If you have a second admin account on your Ubuntu machine, this is the simplest route. Log into that account, open the terminal, and type the command. Replace oldusername with the username you want to change and newusername with what you want it to be.
The full command is:
sudo usermod -l newusername oldusername
The system will ask for your password (the password of the account you are logged into). Type it and press Enter. If the command succeeds, you will see no output — that is normal. If you see an error like "user oldusername does not exist" or "user newusername already exists", check that you spelled both names correctly and that the new name is not already in use on the system.
After the command finishes, the username change is complete. The user can log in with the new username the next time they restart their session or log out and back in.
Renaming the home directory to match the new username
When you change a username with usermod, the home directory keeps its old name. If your old username was james and you change it to jim, your home folder will still be /home/james instead of /home/jim. This works fine — the system does not require them to match — but many people prefer them to be the same for clarity.
To rename the home directory, use the mv command with sudo:
sudo mv /home/oldusername /home/newusername
Again, replace the paths with your actual old and new usernames. The user should not be logged in when you do this. After the rename, the next time that user logs in, their home directory will be in the new location.
If you skip this step, the user's files are still there and still belong to them — nothing breaks. The only downside is that the path looks inconsistent. Some people leave it as is to avoid any risk of interrupting file access during the rename.
Using recovery mode if you have only one account
If you are the only user on the machine, you cannot log into a second account. In this case, boot into recovery mode, which gives you a root shell without needing to log in as any user. Restart your computer and hold down the Shift key as it boots (or press Escape on some systems). You should see a menu. Select "Advanced options for Ubuntu" and then "Recovery mode".
The system will ask you to choose a root shell. Select that option. You will be dropped into a terminal with root access. Now you can run the usermod command without sudo:
usermod -l newusername oldusername
After the command finishes, type exit to leave the recovery shell, then select "Resume" to boot back into your normal desktop. Log in with your new username.
Recovery mode can feel intimidating if you have not used it before, but it is a safe, built-in tool. The system is read-only by default in recovery mode, so you have to explicitly choose to make changes. Just be careful to type the usermod command correctly, because there is no second account to fall back on if something goes wrong.
What happens to file ownership and permissions
When you change a username, the system identifies files by a numeric user ID (UID), not by the name. So all your files keep working — they still belong to you by UID. The username is just a label the system shows you. If you run ls -l in your home directory before and after the change, the UID stays the same, but the name displayed next to it changes.
This means you do not have to change file ownership or permissions. Everything you owned before the username change, you still own after it. Sudo access, group membership, and cron jobs all continue to work because they are tied to the UID, not the name.
The only exception is if you have scripts or configuration files that hardcode your old username as a string. For example, if a cron job refers to /home/oldusername/script.sh, it will break because that path no longer exists (unless you kept the old home directory name). Search your home directory and system config files for references to your old username if you are concerned about this.
Undoing a username change
If you change your username and then realize you made a mistake, you can change it back the same way. Log into a different account or recovery mode and run usermod again with the new name and the old name swapped:
sudo usermod -l oldusername newusername
This is completely safe and reversible. There is no "undo" button, but the command itself is the undo. If you renamed the home directory, you can rename it back with mv the same way you renamed it forward.
The only time a username change becomes hard to undo is if you have already logged in as the new username and created new files or settings. In that case, you have two sets of data to manage. For this reason, it is worth double-checking your new username before you run the command.
Frequently Asked Questions
Can I change my username while I am logged in?
No. The system will not let you change the username of an active user account. You must log out, log into a different account, or use recovery mode. If you try to change your own username while logged in, usermod will return an error saying the user is currently in use.
What if I forget the password for my second admin account?
Use recovery mode instead. Boot into recovery mode, select the root shell, and run usermod there. You do not need a password in recovery mode — physical access to the machine is the only requirement.
Will changing my username break my installed programs?
Most programs will not break because they identify you by UID, not by username. However, programs that hardcode your home directory path (like /home/oldusername) may fail if you also rename your home directory. Check your program settings if you notice issues after the change.
Do I need to change my home directory name too?
No. Your home directory name and your username are separate. The system works fine if they do not match. Rename the directory only if you want them to be consistent for your own clarity.
What if the new username I want is already taken?
The usermod command will refuse and return an error. Choose a different new username and try again. You can check which usernames are already in use by looking at /etc/passwd or running cut -d: -f1 /etc/passwd to see a list.