The usermod command is the standard way to change your username

To change your username in Kali Linux, you use the usermod command with the -l flag, which stands for "login name". The basic syntax is sudo usermod -l newusername oldusername. You must run this command as root or with sudo privileges, and you cannot be logged in as the user you are trying to rename — you need to be logged in as a different user or as root.

Before you run the command, log out of the account you want to rename and log in as root or another user with sudo access. Then open a terminal and type the command. For example, if your current username is "alice" and you want to change it to "alice_work", you would type sudo usermod -l alice_work alice. The system will not ask for confirmation — the change happens when ready.

The usermod command changes only the login name itself. It does not automatically rename your home directory, which by default is located at /home/oldusername. If you want the home directory name to match your new username, you need to rename it separately using the mv command.

Key Takeaways

  • Use sudo usermod -l newusername oldusername to change your login name, and you must be logged in as a different user to do it.
  • Rename your home directory separately with sudo mv /home/oldusername /home/newusername if you want the folder name to match your new username.
  • Update the home directory path in the passwd file by running sudo usermod -d /home/newusername username so the system knows where your home folder is.
  • If you use sudo without a password, you may need to update the sudoers file to reflect your new username, or you will lose passwordless sudo access.

Renaming your home directory to match your new username

After you change your login name with usermod, your home directory still has the old name. This can be confusing because your username and home folder no longer match. To rename the home directory, use the mv command: sudo mv /home/oldusername /home/newusername. This moves the entire folder and everything inside it to the new location.

Once you rename the folder, you must tell the system where your home directory is now. The passwd file stores this information. Update it by running sudo usermod -d /home/newusername newusername. This command updates the home directory path in the passwd file so that when you log in, the system knows to look in the correct location.

After both steps are complete, log out and log back in with your new username. Your home directory should now be at /home/newusername, and the system should recognize it correctly.

Updating sudo access if you have passwordless sudo configured

If you set up your user account to run sudo commands without entering a password, that configuration is stored in the sudoers file under your old username. When you change your username, the sudoers file still references the old name, and you will lose passwordless sudo access.

To fix this, you need to edit the sudoers file. Open a terminal as root and type sudo visudo. This opens the sudoers file in a text editor. Find the line that mentions your old username — it usually looks like oldusername ALL=(ALL) NOPASSWD:ALL — and change "oldusername" to your new username. Save the file and exit. The next time you use sudo, it will work without a password again.

If you are not sure whether you have passwordless sudo set up, try running a sudo command after you change your username. If it asks for a password and you do not remember setting one, you probably do not have passwordless sudo configured, and you can skip this step.

Checking that your username change worked correctly

After you complete all the steps, verify that everything is set up correctly. Log in with your new username and open a terminal. Type whoami and press Enter — it should print your new username. Then type pwd to see your current working directory, which should be /home/newusername.

Run sudo -l to see what sudo permissions you have. This command lists the commands you are allowed to run with sudo. If you set up passwordless sudo, this command should work without asking for a password. If it asks for a password, your passwordless sudo configuration did not transfer correctly, and you may need to edit the sudoers file again.

Check that your files are still accessible by listing the contents of your home directory with ls -la. All your files should be there, and the ownership should show your new username. If the ownership still shows your old username, you may need to run sudo chown -R newusername:newusername /home/newusername to update the file ownership.

What happens to your files and permissions when you change your username

When you change your username with usermod, the system does not automatically update the ownership of your files. Files in your home directory still belong to your old username until you explicitly change them. This can cause permission problems — you might not be able to edit or delete files that should belong to you.

To fix file ownership, use the chown command. The syntax is sudo chown -R newusername:newusername /home/newusername. The -R flag means "recursive", so it updates the ownership of the folder and everything inside it. The first "newusername" sets the user owner, and the second "newusername" sets the group owner. After this command runs, all your files will belong to your new username.

If you have files outside your home directory that belong to your old username, you will need to update those separately. Use sudo chown newusername:newusername /path/to/file for individual files, or use the recursive flag if you want to update an entire folder.

Reversing a username change if you made a mistake

If you change your username and then realize you made a mistake, you can change it back. The process is the same: log in as root or another user, and run sudo usermod -l oldusername newusername. Then rename your home directory back with sudo mv /home/newusername /home/oldusername, and update the passwd file with sudo usermod -d /home/oldusername oldusername.

If you also updated file ownership, you will need to change it back as well: sudo chown -R oldusername:oldusername /home/oldusername. If you edited the sudoers file, open it again with sudo visudo and change your username back to the original.

The key point is that none of these changes are permanent — you can undo them by running the same commands in reverse. Take your time and double-check each step before you press Enter.

Why you might want to change your username and when to do it

Most people change their username because they want a name that is easier to type, more professional, or straightforward different from what they chose when they first set up their system. Some people change it for privacy reasons, or because they inherited a machine with someone else's username on it.

The best time to change your username is right after you set up Kali Linux, before you have created many files or configured complex permissions. If you have been using the system for a long time and have many files, groups, and permissions tied to your old username, the change becomes more complicated because you have to update ownership and permissions in more places.

If you are running Kali Linux on a machine that is part of a network or domain, changing your username locally may cause problems with network authentication or shared resources. Check with your network administrator before you change your username on a networked machine.

Frequently Asked Questions

Can I change my username while I am logged in as that user?

No. You must be logged in as a different user or as root. If you try to change your username while logged in as that user, the system will refuse because the user account is currently in use. Log out, log in as root or another user, and then run the usermod command.

What if I forget to rename my home directory after changing my username?

Your old home directory will still exist at /home/oldusername, but the system will not automatically use it. You can rename it later with sudo mv /home/oldusername /home/newusername and update the passwd file. Your files will not be deleted — they will just be in the wrong location until you move them.

Do I need to change my password when I change my username?

No. Your password is stored separately from your username and does not change when you rename your account. You will log in with your new username and the same password you used before.

Will changing my username break any programs I have installed?

Most programs will not break, but some may have configuration files that reference your old username. If a program stops working after you change your username, check its configuration files and update any references to your old username. Configuration files are usually in your home directory under a folder that starts with a dot, like .config or .bashrc.

What if I do not have sudo access?

You cannot change your username without root or sudo privileges. If you do not have sudo access, you will need to ask someone with root access to run the usermod command for you, or you will need to boot into single-user mode or recovery mode to gain root access.