
Observe ZDNET: Add us as a most well-liked supply on Google.
The usermod command is brief for person modification, and, because the identify implies, lets you modify varied elements of a person account.
For a Linux administrator, this command is essential. For Linux customers, the command most actually turns out to be useful, particularly given what it will possibly do.
Let’s dive down this rabbit gap and see what’s what with the Linux usermod command.
1. Change person particulars
Whenever you create a Linux person with the adduser command, you possibly can embrace sure particulars to associate with the brand new person (similar to full identify, workplace and residential cellphone numbers, and different data, which can be utilized as an outline. After you’ve got created the person, the one solution to change or add such data is through the usermod command. Say, for example, you need to add a remark for a person. To try this, you’ll subject the command:
sudo usermod -c “INFORMATION” USER
Additionally: 5 surprisingly productive issues you are able to do with the Linux terminal
The place INFORMATION is what you need to add, and USER is the person account you need to change.
This may be useful when you have two customers with the identical first identify and also you need to differentiate them of their person data.
2. Change a username
You can too change a username. Earlier than you do that, know that it doesn’t change the person’s dwelling listing identify. So if I’ve the person sam and I need to change it to samantha, usermod is there to assist me. Such a command would seem like this:
sudo usermod -l samantha sam
The -l possibility is for the login identify.
3. Rename a house listing
After you modify a username, you may additionally need to rename the person’s dwelling listing. Earlier than you do that, you will need to be certain that the person is logged out; in any other case, it might wreak havoc on their account (or their information). You additionally must ensure that the person’s information is added to the brand new dwelling listing (in any other case, the person winds up with an empty dwelling). To alter a listing identify (and add the information), you’ll use a command like this (sticking with our sam/samantha instance):
sudo usermod -d /dwelling/samantha -m sam
The -d possibility units the brand new dwelling listing path, and the -m possibility strikes the information.
Additionally: There is a new coolest Linux distribution able to wow you
4. Lock and unlock a person’s account
There could also be occasions when you’ll want to lock a person out of their account (and later enable them again in). This could possibly be used for non permanent workers or grounded youngsters. To lock a person account, the command could be:
sudo usermod -L USER
The place USER is the username to which the lock applies.
To unlock the account, you’ll subject the command:
sudo usermod -U USER
The place USER is the person account.
6. Change a person’s account expiry date
Do you know you possibly can expire a person account in Linux? For instance you could have a temp worker whose contract ends on October 31, 2025. If you wish to set the particular person’s person account to run out on that date (as an alternative of getting to recollect it when the date arrives), you need to use the expiry function of usermod like so:
sudo usermod -e 2025-10-31 USER
The place USER is the person account identify.
7. Add a person to a bunch (or teams)
I’ve had to make use of this function so many occasions. For instance, I take advantage of Docker lots, and after I set up it, I’ve so as to add customers to the group (in any other case it will not work for them with out utilizing sudo, which may result in safety points). You may need additionally created a bunch that will probably be utilized by a number of accounts to entry a particular folder. For instance you’ve got created the editorial group and need to add sam to it. The command for that will be:
sudo usermod -aG editorial sam
Additionally: 7 Linux terminal fundamentals each newbie ought to be taught first – and why
8. Modify a person’s dwelling listing
In case you’ve renamed a person account, you will discover their dwelling listing continues to be listed as the unique username. If you need to rename the person’s dwelling listing (to keep away from confusion), usermod has your again. Earlier than you do that, nonetheless, it is essential that you just be certain the person is logged out of their account (in any other case, it might trigger severe issues).
To alter the identify of a person’s dwelling listing, the command could be:
sudo usermod -d /dwelling/NEWNAME OLDNAME
The place NEWNAME is the brand new identify for the listing and OLDNAME is the present identify.
9. Change a person’s shell
Chances are high fairly slim that you’re going to ever want to do that, however you possibly can change a person’s shell. For instance you need to change samantha’s shell from bash to zsh. To try this, it’s best to first be certain the brand new shell is definitely put in with the command:
cat /and so forth/shells
If zsh is listed, you possibly can change it for samantha with the next command:
sudo usermod -s /bin/SHELL samantha
Wish to observe my work? Add ZDNET as a trusted supply on Google.