Usermod Command in Unix-like Systems
In Unix-like operating systems, effective user management is crucial. Among all commands available, usermod
command is used to modifying user account properties. In this comprehensive guide, we sive deep into the usermod
command and exploring its various options with example
-c, --comment COMMENT
: Add a comment to the user account.usermod -c "John Doe" username
This command adds a comment "John Doe" to the user account with the username "username".
-d, --home HOME_DIR
: Set the user's home directory.usermod -d /home/newhome username
This command changes the home directory of the user with the username "username" to "/home/newhome".
-e, --expiredate EXPIRE_DATE
: Set the account expiration date.usermod -e 2024-12-31 username
This command sets the account expiration date for the user with the username "username" to December 31, 2024.
-f, --inactive INACTIVE
: Set the number of inactive days before an account is disabled.usermod -f 30 username
This command sets the number of inactive days to 30 before the account for the user with the username "username" is disabled.
-g, --gid GROUP
: Set the user's primary group.usermod -g newgroup username
This command changes the primary group of the user with the username "username" to "newgroup".
-G, --groups GROUPS
: Add the user to additional groups.usermod -G group1,group2 username
This command adds the user with the username "username" to the additional groups "group1" and "group2".
-a, --append
: Add the user to the supplementary group(s), in addition to the current group(s).usermod -aG supplementarygroup username
This command adds the user with the username "username" to the supplementary group "supplementarygroup" without removing them from their current group(s).
-h, --help
: Display help message and exit.usermod --help
This command displays the help message for the
usermod
command, providing information on its usage and options.-l, --login NEW_LOGIN
: Change the login name of the user.usermod -l newusername oldusername
This command changes the login name of the user from "oldusername" to "newusername".
-L, --lock
: Lock the user account.usermod -L username
This command locks the account of the user with the username "username", preventing them from logging in.
-m, --move-home
: Move the content of the user's home directory to the new location.usermod -m -d /newhome username
This command moves the content of the user's home directory to a new location "/newhome" and updates the home directory path.
-o, --non-unique
: Allow using a non-unique UID.usermod -o -u 1001 username
This command allows the user with the username "username" to have a non-unique UID (user ID) by specifying the
-o
option.-p, --password PASSWORD
: Set the user's password to the specified encrypted password.usermod -p '$6$DmQX4M8E$6OAl6DSAX1Yv2y3FyDpE11WEdM/7D1AUViWfQTowqVg6GwxjcA3xjZpM0gibklW77ZftXMHxvUvWbuP3CJg.1' username
This command sets the user's password to the specified encrypted password.
-s, --shell SHELL
: Set the user's login shell.usermod -s /bin/bash username
This command changes the login shell of the user with the username "username" to "/bin/bash".
-u, --uid UID
: Set the user's UID (user ID).usermod -u 1001 username
This command changes the UID (user ID) of the user with the username "username" to 1001.
-U, --unlock
: Unlock the user account.usermod -U username
This command unlocks the previously locked account of the user with the username "username", allowing them to log in again.
Subscribe to my newsletter
Read articles from Shubham Bandgar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Shubham Bandgar
Shubham Bandgar
Red Hat Certified Engineer