usermod command is used to modify the basic information of a user account in Linux. This command can be used to change a user’s home directory, default shell, UID, GID, and other account-related information.
The basic syntax for the
usermod command is as follows:
usermod [options] username
options represent the various flags and arguments that can be used with the
usermod command, and
username is the name of the user account that you want to modify.
For example, to change the default shell of a user account to
/bin/bash, you can use the following command:
usermod -s /bin/bash username
Similarly, to change the home directory of a user account to
/home/newdir, you can use the following command:
usermod -d /home/newdir username
The following table lists the available options for the
|-c, –comment COMMENT||Add a comment to the user’s account|
|-d, –home HOME_DIR||Change the user’s home directory|
|-e, –expiredate EXPIRE_DATE||Set the expiration date for the user’s account|
|-f, –inactive INACTIVE||Set the number of days after password expiration that the account will be disabled|
|-g, –gid GROUP||Change the user’s primary group|
|-G, –groups GROUPS||Change the user’s supplementary groups|
|-h, –help||Display help information|
|-l, –login NEW_LOGIN||Change the user’s login name|
|-L, –lock||Lock the user’s account|
|-m, –move-home||Move the user’s home directory to the new location|
|-o, –non-unique||Allow the use of duplicate UIDs|
|-p, –password PASSWORD||Set the user’s password|
|-R, –root CHROOT_DIR||Apply changes in the CHROOT_DIR directory|
|-s, –shell SHELL||Change the user’s default shell|
|-u, –uid UID||Change the user’s UID|
|-U, –unlock||Unlock the user’s account|
|-Z, –selinux-user SEUSER||Change the SELinux user for the user’s login|
- If you encounter an error message stating that the user account is currently in use, make sure that the user is not logged in or running any processes before attempting to modify their account information.
- If you encounter an error message stating that the user account does not exist, double-check the spelling of the username and ensure that the account has been created before attempting to modify it.
usermodcommand should be used with caution, as it can potentially cause issues with system stability and security if used improperly.
- It is recommended to create a backup of the system before making any changes to user account information using the