usermod
user managementLinux/Unix
The usermod command is one of the most frequently used commands in Linux/Unix-like operating systems. usermod Modify a user account
Quick Reference
Command Name:
usermod
Category:
user management
Platform:
Linux/Unix
Basic Usage:
usermod [options] [arguments]
Common Use Cases
Syntax
usermod [options] LOGIN
Options
Option | Description |
---|---|
-a, --append |
Append the user to the supplemental groups mentioned by the -G option without removing the user from other groups |
-c, --comment COMMENT |
New value of the GECOS field |
-d, --home HOME_DIR |
New home directory for the user account |
-e, --expiredate EXPIRE_DATE |
Set account expiration date to EXPIRE_DATE (YYYY-MM-DD format) |
-f, --inactive INACTIVE |
Set password inactive after expiration to INACTIVE days |
-g, --gid GROUP |
Force use GROUP as new primary group |
-G, --groups GROUPS |
New list of supplementary GROUPS |
-h, --help |
Display help message and exit |
-l, --login NEW_LOGIN |
New value of the login name |
-L, --lock |
Lock the user account |
-m, --move-home |
Move contents of the home directory to the new location (use only with -d) |
-o, --non-unique |
Allow using duplicate (non-unique) UID |
-p, --password PASSWORD |
Use encrypted password for the new password |
-R, --root CHROOT_DIR |
Directory to chroot into |
-P, --prefix PREFIX_DIR |
Prefix directory where are located the /etc/* files |
-s, --shell SHELL |
New login shell for the user account |
-u, --uid UID |
New UID for the user account |
-U, --unlock |
Unlock the user account |
-v, --add-subuids FIRST-LAST |
Add range of subordinate uids |
-V, --del-subuids FIRST-LAST |
Remove range of subordinate uids |
-w, --add-subgids FIRST-LAST |
Add range of subordinate gids |
-W, --del-subgids FIRST-LAST |
Remove range of subordinate gids |
-Z, --selinux-user SEUSER |
New SELinux user mapping for the user account |
Examples
How to Use These Examples
The examples below show common ways to use the usermod
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
# Change a user's home directory
sudo usermod -d /newhome/johndoe johndoe