The Two Ways to Change Your Linux Username

You can change your Linux username in two ways: by using the usermod command if you have administrator access, or by creating a new account and transferring your files. The usermod method is faster and keeps your user ID the same, which matters if you have files or permissions tied to that ID. The new-account method is safer if something goes wrong, because your old account stays intact until you delete it.

Both methods require you to be logged in as root or to have sudo privileges. If you do not have either, you will need to ask your system administrator to make the change for you.

Key Takeaways

  • The usermod command changes your username while keeping your user ID and home directory intact, and is the fastest method for most people.
  • You cannot change your own username while you are logged in under that account — you must switch to root or another user first.
  • After changing your username, you should rename your home directory to match, or your system may create a new one and leave your files behind.
  • If usermod fails or you are unsure about the process, creating a new account and copying your files is safer and reversible.

Using usermod to Change Your Username

Open a terminal and log in as root, or use sudo. Type the following command, replacing oldname with your current username and newname with what you want it to be:

sudo usermod -l newname oldname

This changes the login name in the system files. The command runs silently if it succeeds — no message means it worked. If you see an error like "usermod: user oldname is currently logged in", you are still logged in under the old account. Log out, switch to root, or open another terminal as a different user, then try again.

After the username changes, your home directory still has the old name. Rename it to match by typing:

sudo mv /home/oldname /home/newname

If you skip this step, your system may create a new home directory the next time you log in, and your files will stay in the old one. You can move them later, but it is easier to do it now.

Verify the Change Worked

Log out completely and log back in with your new username. Open a terminal and type whoami — it should print your new username. Type pwd to see your current directory; it should show /home/newname.

Check that your files are still there by typing ls. If you see your documents, desktop, and other folders, the change is complete. If the directory is empty or you cannot find your files, they are still in the old home directory at /home/oldname. You can move them with the command sudo mv /home/oldname/* /home/newname/ and then delete the old directory with sudo rmdir /home/oldname.

What to Do If usermod Fails

The most common reason usermod fails is that you are still logged in under the account you are trying to change. Log out completely, switch to the root account, or open a new terminal window as a different user. Then run the command again.

If you see "usermod: user oldname does not exist", check that you spelled the username correctly. Type cat /etc/passwd to see a list of all usernames on the system.

If usermod runs but your files disappear or your permissions break, do not panic. Your files are still on the disk. Log in as root and move them back to the correct location, or restore from a backup if you have one. This is rare, but it is why creating a new account first is the safer choice if you are unsure.

Creating a New Account Instead

If you want to be extra careful, create a new account with your desired username, copy your files over, and then delete the old account. This way, if something goes wrong, your original account is still there.

First, create the new account. Type sudo useradd -m -s /bin/bash newname. The -m flag creates a home directory, and -s /bin/bash sets your shell to bash. Then set a password with sudo passwd newname.

Copy your files from the old account to the new one. Type sudo cp -r /home/oldname/* /home/newname/. Then fix the ownership so the new account owns the files: sudo chown -R newname:newname /home/newname.

Log in with your new username and verify everything is there. Once you are sure, delete the old account with sudo userdel -r oldname. The -r flag removes the home directory too.

Changing Your Username on Different Linux Distributions

The usermod command works the same way on Ubuntu, Debian, Fedora, CentOS, and most other distributions. Some systems may require you to install usermod if it is not already there — on Debian and Ubuntu, it comes with the passwd package, which is installed by default.

If you are using a graphical desktop like GNOME or KDE, you may also be able to change your username through the Settings app under Users or Accounts. Look for an option to edit your account details. The graphical method does the same thing as usermod but may handle the home directory rename automatically, so it is worth trying first if you are uncomfortable with the terminal.

What Happens to Your Files and Permissions

When you change your username with usermod, your user ID stays the same. This matters because Linux stores file ownership by user ID, not by name. Your files will still belong to you after the change, even though the name attached to that ID is different.

If you have set up sudo privileges, SSH keys, or cron jobs under your old username, they will still work after the change. However, if you have scripts or configuration files that reference your username by name, you may need to update them manually. Search for your old username in your home directory with grep -r oldname ~ to find any references.

Frequently Asked Questions

Can I change my username without logging out?

No. You cannot change the username of an account while you are logged in under it. Log out completely, switch to root in a new terminal, or use another user account to run the usermod command.

What if I forget my old username?

Type whoami in a terminal to see your current username. If you are already logged in, this will show it. If you need a list of all usernames on the system, type cat /etc/passwd as root.

Will changing my username break my programs or settings?

Most programs store settings in hidden folders in your home directory and do not care what your username is. However, if you have shell scripts, cron jobs, or configuration files that reference your old username by name, you will need to update them. Your user ID stays the same, so file ownership and permissions will not break.

Can I change my username if I do not have sudo access?

No. You need root or sudo privileges to run usermod or create a new account. Ask your system administrator to make the change for you, or to give you temporary sudo access.

What should I do if my home directory is empty after the change?

Your files are still in the old directory at /home/oldname. Move them to the new location with sudo mv /home/oldname/* /home/newname/, then delete the old directory with sudo rmdir /home/oldname. This usually happens if you forgot to rename the home directory after running usermod.