Linux is a multi-user operating system. And with this feature comes the responsibility of managing every user on the system. The administrator needs to ensure that each user has proper permissions, distinct user IDs, unique user names, etc.
But what if you want to change the information associated with a particular user? Does Linux allow anyone to modify such sensitive details easily? The usermod command is the answer to all these questions.
This article will demonstrate how you can change your username on Linux, along with a detailed guide on modifying the user ID and home directory of a user.
Change a Username on Linux
On Linux, the /etc/passwd file stores the information associated with users. Although you can modify the user details directly by editing the passwd file, it is not a recommended practice since it can lead to various issues on your system.
You can use the usermod utility provided by Linux to perform operations related to user management and moderation. The usermod command even allows you to change the username of a user on Linux.
Note that you must have access to a superuser account to issue these commands successfully. If you don’t have the authorization, you can ask your system administrator to add you to the sudoers list.
To change the username, use the -l flag with usermod:
usermod -l newusername oldusername
For example, to change the username of the user “makeuseof” to “muo”:
usermod -l muo makeuseof
Rename the Home Folder
Changing the username on Linux using the aforementioned command doesn’t modify the home directory of that particular user. Use the -d flag if you want the home folder to reflect the changes made to the username.
To rename the home directory of the user muo:
usermod -d /home/muo -m muo
To verify if the aforementioned command works, head over to the home directory and locate the folder named muo.
Assign a New User ID to a User
Apart from changing the username, the usermod command also allows you to assign a new and unique UID to any user. The UID is a non-negative integer starting from zero. UIDs between the range 0-99 are reserved for system users.
To change the user ID on Linux using usermod:
usermod -u uid username
…where uid is the user ID that you want to assign to the user named username.
When you change the UID, the system will add the new UID as the owner of all the files and folders present in the /home directory of that particular user.
Note that the user will have to change the owner details of any files outside the /home directory.
Change a User’s Display Name
The username and user ID are important for identifying a particular user on the system. Apart from these two, Linux also stores additional “finger information” related to users in the /etc/passwd file. This information includes the display name, office phone, and work phone of the user.
Although users have a complete choice whether they want to provide such information, Linux allows you to change or remove these details anytime you want.
You can modify your account’s display name using either usermod or the chfn command.
Using the usermod Command
Specify the -c flag along with the usermod command to change the display name:
usermod -c "First Last" username
For example, if you want to change the display name of the user muo:
usermod -c "Make UseOf" muo
Using the chfn Command
Changing the display name using the chfn command is simple:
sudo chfn -f "First Last" username
To modify the display name of the user makeuseof:
sudo chfn -f "Make UseOf" makeuseof
Managing User Information on Linux
Since Linux offers so many options related to user management, the need for a special user with elevated privileges is obvious. That is why, every Linux system has a root user, or a superuser, that controls and monitors the activities of other users on the system.
To add an extra layer of security and ensure that every user is isolated from the rest, Linux offers the choice to add a password to your account. If you have already set up a weak password without giving much thought, consider changing it to enhance the security of your account.
Need to change your Linux password? Here’s everything you need to know about resetting a password in Linux.
About The Author