The usermod command changes your username from the terminal

The fastest way to change your Linux username is the usermod command, which modifies user account details directly. You run it from the terminal with your old username, new username, and the -l flag (the letter L, for "login"). The command looks like this: sudo usermod -l newusername oldusername. You need sudo permission to run it, which means your account must be in the sudoers group.

The usermod method works on most Linux distributions — Ubuntu, Debian, Fedora, CentOS, and others — because usermod is part of the standard user management toolkit. It changes only the username itself, not the home directory path. If you want to rename the home directory at the same time, you will need a second command after usermod completes.

One important detail: you cannot change the username of the account you are currently logged into. You must either log into a different account with sudo permission, or use the root account. If you are the only user on the machine, you will need to boot into single-user mode or use a live USB to make the change.

Key Takeaways

  • The usermod command with the -l flag changes your username: sudo usermod -l newusername oldusername.
  • You cannot change the username of the account you are currently logged into; you must switch to a different account with sudo permission first.
  • Usermod changes only the username, not the home directory path, so your files stay in /home/oldusername unless you rename the folder separately.
  • After changing the username, you may need to update configuration files or scripts that reference the old username.

Step-by-step: changing your username with usermod

Open a terminal and log into an account with sudo permission — not the account whose username you want to change. If you are on a single-user system, you will need to restart into single-user mode or use a live USB instead.

Type the usermod command with your old and new usernames. 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 when prompted. The command runs silently — no message means it worked. To verify the change took effect, type cat /etc/passwd | grep newusername. You should see a line with your new username listed.

If you want to rename the home directory as well, use the mv command to move the folder:

sudo mv /home/oldusername /home/newusername

After renaming the home directory, you should also update the home directory path in the passwd file. Use usermod again with the -d flag to point to the new location:

sudo usermod -d /home/newusername newusername

Why you cannot change your own username while logged in

Linux prevents you from changing the username of an active session because the system is still using that username to track permissions, running processes, and file ownership. If you tried to change it mid-session, the system would lose track of which files belong to you and which processes you own. This can corrupt your session or leave the account in an unusable state.

The workaround is to log into a different account — a second user account, the root account, or single-user mode — and run usermod from there. The account you are changing does not need to be logged in at all; usermod works on any username in the system.

Renaming the home directory at the same time

When you change your username with usermod alone, your home directory stays at /home/oldusername. This creates a mismatch: your username is new but your files are in a folder with the old name. Most of the time this does not cause problems, but it looks messy and can confuse scripts or tools that expect the username and home directory to match.

To rename the home directory, first change the username with usermod, then move the folder with sudo mv /home/oldusername /home/newusername. After that, update the home directory path in the system files with sudo usermod -d /home/newusername newusername. Do these steps in order — if you move the folder before updating the path, the system will not know where to find your home directory.

Check that the change worked by typing cat /etc/passwd | grep newusername. Look for the line with your new username and verify that the home directory path shows /home/newusername.

What happens to files and permissions after the change

Files you own keep their content and location, but the system updates their ownership records to show your new username. When you type ls -l in your home directory, you will see your new username listed as the owner instead of the old one. The file permissions themselves do not change — only the name associated with those permissions.

If you have files outside your home directory that you own, they also update to show the new username. However, if you have configuration files or scripts that hardcode your old username as a string (not as a permission), those will not update automatically. You will need to find and edit those files by hand. Common places to check are ~/.bashrc, ~/.bash_profile, ~/.config, and any cron jobs you have set up.

Changing your username on a single-user system

If you are the only user on the machine, you cannot log into a different account to run usermod. Instead, you need to restart into single-user mode or boot from a live USB.

To use single-user mode, restart your computer and hold down Shift during boot (on most systems). You should see a GRUB menu. Select the entry that says "recovery mode" or "single-user mode". The system will boot into a root shell without loading the full desktop. From there, you can run usermod normally: usermod -l newusername oldusername. You do not need sudo in single-user mode because you are already root.

If single-user mode does not work on your system, you can use a live USB instead. Boot from a Linux live USB, open a terminal, and run usermod with the full path to the target system's files. This is more complex and usually not necessary, so try single-user mode first.

Frequently Asked Questions

What if I forget my password and cannot log into another account?

You will need to boot into single-user mode or use a live USB to change the username without a password. Single-user mode is faster: restart, hold Shift, select recovery mode, and run usermod from the root shell. If your system does not support recovery mode, a live USB gives you the same access.

Do I need to change anything else after changing my username?

The system updates file ownership automatically, but you should check configuration files that mention your old username by name. Search your home directory with grep -r oldusername ~ to find files that reference it. Edit those files to use your new username instead.

Can I change my username back to the old one if I change my mind?

Yes. Run usermod again with the names reversed: sudo usermod -l oldusername newusername. If you renamed the home directory, move it back with sudo mv /home/newusername /home/oldusername and update the path with sudo usermod -d /home/oldusername oldusername.

What if usermod says the username is already in use?

Another account already has that username. Type cat /etc/passwd to see all usernames on the system and pick a different name. Usernames must be unique.

Does changing my username affect my sudo permission?

Not if your sudo access is based on group membership. If your account is in the sudoers group, you keep sudo permission after the name change. If sudo was set up for your specific old username, you will lose it and need an administrator to update the sudoers file.