The usermod command is used with various options to modify the existing user account parameters. The usermod --help command will display the various options that can be used. The syntax of usermod is as follows:
$ usermod -<option> <username>
The following table lists the common options used with usermod and their descriptions:
Options |
Description |
usermod -c "Comments" <username> |
Add comments, such as the user's full name, address, phone number, and so on, in the GECOS field. |
usermod -g <gid> <username> |
Modify the user's primary group. |
usermod -G <groupname> <username> |
Modify the user's secondary group. |
usermod -a -G <groupname> <user> |
Used with the -G option only. It appends the user to the secondary group mentioned, without removing the user from other groups. |
usermod -s <shell> <username> |
Modify the login shell of the user account. |
usermod -L <username> |
Lock a user account. |
usermod -U <username> |
Unlock a user account. |
An example of using the usermod command to modify the user's login shell is shown in the following screenshot:
The following command is used to view the associated groups of a user:
$ groups <username>
$ groups sam
The usermod command can be used to add a new secondary group in the existing secondary groups of a user. The following command will add a new secondary group wheel in the existing secondary groups of user sam as shown in the following screenshot: