How to Change the username or userID in Kali Linux?
Last Updated :
19 Sep, 2024
Kali Linux, a popular Linux distribution for penetration testing and ethical hacking, allows users to create a username during installation, automatically assigning a unique User ID (UID) to each user for identification. However, there are situations where you might need to change the username or user ID, such as when renaming accounts for clarity or security purposes.
Here, we’ll show you how to efficiently modify usernames and user IDs using the powerful ‘usermod‘ command in Kali Linux.
What is the ‘usermod’ Command?
The ‘usermod‘ command in Linux is a tool used to modify user account details, including the username and User ID (UID). It is a part of the Linux user management utilities, which also include commands like ‘useradd’ and ‘userdel’. The ‘usermod’ command allows system administrators to change account details, making it easier to update usernames and UIDs as needed without affecting the user’s data or permissions.
Understanding User ID and Username in Linux
But before changing the username or user ID we shall be aware of what is the user ID or username.
- User ID (UID): A unique identifier assigned to each user on a Linux system. It is used by the system to differentiate between users, even if they share the same username.
- Username: A human-readable identifier assigned to a user for login purposes.
User account details, including the UID, username, full name, default shell, and more, are stored in the ‘/etc/passwd‘ file. Meanwhile, password-related details like password hashes are stored in the ‘/etc/shadow‘ file.
Steps to Change the username or userID in Kali Linux
Let us look at the various steps to change the username in Kali Linux.
1. To get the user id of a user
cat /etc/passwd | grep oldusername
Replace the ‘oldusername’ with the name of the user you want to use.
This will display us a few details of the user along with the userid.
2. To change the Username
To change the username of an existing user, use the usermod command with the ‘-l’ option:
usermod -l newusername oldusername
Replace the ‘oldusername’ with the name of the user you want to change.
- oldusername: The current username you want to change.
- newusername: The new username you wish to assign to the user.
This command will change the username of the oldusername to the newusername but will not change the files and userID of the user.
3. To change the UserID
We use ‘usermod’ command along with ‘-u’ parameter in order to change the userid of a particular user.
usermod -u 1234 newusername
- Replace the newusername with the username you want to change the id of.
- Replace 1234 with the id you want to set for the user.
This command will change the userid of the user from the default one to 1234.
Conclusion
Changing usernames and User IDs in Kali Linux using the usermod command is a straightforward process that provides flexibility in managing user accounts. By following the steps outlined in this guide, you can efficiently modify usernames and UIDs without disrupting system functionality. Always verify your changes and ensure proper file ownership to maintain system integrity.
How to Change the username or userID in Kali Linux? – FAQs
Can I change both the username and the User ID (UID) at the same time?
Yes, you can change both the username and the UID, but these changes should be done carefully. First, use the usermod ‘-l’ option to change the username, and then use the usermod ‘-u’ option to update the UID. It’s essential to verify that the changes are reflected and that file ownership has been updated accordingly.
Does changing the username affect the user’s files and permissions?
No, changing the username with the usermod ‘-l’ command does not affect the user’s files or permissions. However, if you want to rename the user’s home directory to match the new username, you will need to do so manually using the mv command and update the home directory path with usermod ‘-d’.
How do I ensure file ownership is updated after changing the UID?
After changing the UID, you must update the ownership of the user’s files. You can do this by running the following command:
sudo find / -user oldUID -exec chown -h newUID {} \;
This command updates the ownership of all files and directories associated with the old UID to the new UID.
Can I change the username while the user is logged in?
It is not recommended to change the username or UID while the user is logged in, as it may cause issues with running processes. You should log the user out first, or forcefully terminate their session using:
pkill -u username
Then proceed with the username or UID change.