Linux "usermod" Command Line Options and Examples
modify a user account

The usermod command modifies the system account files to reflect the changes that are specified on the command line..


Usage:

usermod [options] LOGIN






Command Line Options:

-a
Add the user to the supplementary group(s). Use only with the -G option.
usermod -a ...
-c
The new value of the user's password file comment field. It is normally modified using the chfn(1)utility.
usermod -c ...
-d
The user's new login directory.If the -m option is given, the contents of the current home directory will be moved to the new homedirectory, which is created if it does not already exist.
usermod -d ...
-e
The date on which the user account will be disabled. The date is specified in the format YYYY-MM-DD.An empty EXPIRE_DATE argument will disable the expiration of the account.This option requires a /etc/shadow file. A /etc/shadow entry will be created if there were none.
usermod -e ...
-f
The number of days after a password expires until the account is permanently disabled.A value of 0 disables the account as soon as the password has expired, and a value of -1 disables thefeature.This option requires a /etc/shadow file. A /etc/shadow entry will be created if there were none.
usermod -f ...
-g
The group name or number of the user's new initial login group. The group must exist.Any file from the user's home directory owned by the previous primary group of the user will be owned bythis new group.The group ownership of files outside of the user's home directory must be fixed manually.
usermod -g ...
-G
A list of supplementary groups which the user is also a member of. Each group is separated from the nextby a comma, with no intervening whitespace. The groups are subject to the same restrictions as the groupgiven with the -g option.If the user is currently a member of a group which is not listed, the user will be removed from the group.This behaviour can be changed via the -a option, which appends the user to the current supplementary grouplist.
usermod -G ...
-l
The name of the user will be changed from LOGIN to NEW_LOGIN. Nothing else is changed. In particular, theuser's home directory or mail spool should probably be renamed manually to reflect the new login name.
usermod -l ...
-L
Lock a user's password. This puts a '!' in front of the encrypted password, effectively disabling thepassword. You can't use this option with -p or -U.Note: if you wish to lock the account (not only access with a password), you should also set theEXPIRE_DATE to 1.
usermod -L ...
-m
Move the content of the user's home directory to the new location.This option is only valid in combination with the -d (or --home) option.usermod will try to adapt the ownership of the files and to copy the modes, ACL and extended attributes,but manual changes might be needed afterwards.
usermod -m ...
-o
When used with the -u option, this option allows to change the user ID to a non-unique value.
usermod -o ...
-p
The encrypted password, as returned by crypt(3).Note: This option is not recommended because the password (or encrypted password) will be visible by userslisting the processes.The password will be written in the local /etc/passwd or /etc/shadow file. This might differ from thepassword database configured in your PAM configuration.You should make sure the password respects the system's password policy.
usermod -p ...
-R
Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory.
usermod -R ...
-s
The name of the user's new login shell. Setting this field to blank causes the system to select thedefault login shell.
usermod -s ...
-u
The new numerical value of the user's ID.This value must be unique, unless the -o option is used. The value must be non-negative.The user's mailbox, and any files which the user owns and which are located in the user's home directorywill have the file user ID changed automatically.The ownership of files outside of the user's home directory must be fixed manually.No checks will be performed with regard to the UID_MIN, UID_MAX, SYS_UID_MIN, or SYS_UID_MAX from/etc/login.defs.
usermod -u ...
-U
Unlock a user's password. This removes the '!' in front of the encrypted password. You can't use thisoption with -p or -L.Note: if you wish to unlock the account (not only access with a password), you should also set theEXPIRE_DATE (for example to 99999, or to the EXPIRE value from /etc/default/useradd).
usermod -U ...
-v
Add a range of subordinate uids to the user's account.This option may be specified multiple times to add multiple ranges to a users account.No checks will be performed with regard to SUB_UID_MIN, SUB_UID_MAX, or SUB_UID_COUNT from/etc/login.defs.
usermod -v ...
-V
Remove a range of subordinate uids from the user's account.This option may be specified multiple times to remove multiple ranges to a users account. When both
usermod -V ...
-w
Add a range of subordinate gids to the user's account.This option may be specified multiple times to add multiple ranges to a users account.No checks will be performed with regard to SUB_GID_MIN, SUB_GID_MAX, or SUB_GID_COUNT from/etc/login.defs.
usermod -w ...
-W
Remove a range of subordinate gids from the user's account.This option may be specified multiple times to remove multiple ranges to a users account. When both
usermod -W ...
-Z
The new SELinux user for the user's login.A blank SEUSER will remove the SELinux user mapping for user LOGIN (if any).CAVEATSYou must make certain that the named user is not executing any processes when this command is being executedif the user's numerical user ID, the user's name, or the user's home directory is being changed. usermodchecks this on Linux. On other platforms it only uses utmp to check if the user is logged in.You must change the owner of any crontab files or at jobs manually.You must make any changes involving NIS on the NIS server.CONFIGURATIONThe following configuration variables in /etc/login.defs change the behavior of this tool:MAIL_DIR (string)The mail spool directory. This is needed to manipulate the mailbox when its corresponding user account ismodified or deleted. If not specified, a compile-time default is used.MAIL_FILE (string)Defines the location of the users mail spool files relatively to their home directory.The MAIL_DIR and MAIL_FILE variables are used by useradd, usermod, and userdel to create, move, or delete theuser's mail spool.MAX_MEMBERS_PER_GROUP (number)Maximum members per group entry. When the maximum is reached, a new group entry (line) is started in/etc/group (with the same name, same password, and same GID).The default value is 0, meaning that there are no limits in the number of members in a group.This feature (split group) permits to limit the length of lines in the group file. This is useful to makesure that lines for NIS groups are not larger than 1024 characters.If you need to enforce such limit, you can use 25.Note: split groups may not be supported by all tools (even in the Shadow toolsuite). You should not usethis variable unless you really need it.SUB_GID_MIN (number), SUB_GID_MAX (number), SUB_GID_COUNT (number)If /etc/subuid exists, the commands useradd and newusers (unless the user already have subordinate groupIDs) allocate SUB_GID_COUNT unused group IDs from the range SUB_GID_MIN to SUB_GID_MAX for each new user.The default values for SUB_GID_MIN, SUB_GID_MAX, SUB_GID_COUNT are respectively 100000, 600100000 and10000.SUB_UID_MIN (number), SUB_UID_MAX (number), SUB_UID_COUNT (number)If /etc/subuid exists, the commands useradd and newusers (unless the user already have subordinate userIDs) allocate SUB_UID_COUNT unused user IDs from the range SUB_UID_MIN to SUB_UID_MAX for each new user.The default values for SUB_UID_MIN, SUB_UID_MAX, SUB_UID_COUNT are respectively 100000, 600100000 and10000.FILES/etc/groupGroup account information./etc/gshadowSecure group account information./etc/login.defsShadow password suite configuration./etc/passwdUser account information./etc/shadowSecure user account information./etc/subgidPer user subordinate group IDs./etc/subuidPer user subordinate user IDs.
usermod -Z ...