usermod(8)
Modify a user account's login name, UID, groups, home directory, shell, and other attributes.
Synopsis
usermod [OPTION]... LOGINDescription
usermod modifies the system account files to reflect the changes that are specified on the command line. The changes are restricted by the permissions of the invoking user. Only the superuser can make unrestricted changes; ordinary users can only modify their own password, gecos field, and login shell.
usermod is commonly used to add a user to a group, change their home directory, or update their login shell without recreating the entire account.
Common options
| Flag | What it does |
|---|---|
-a, --append | Append the user to supplementary groups; only use with -G (prevents removing from other groups) |
-c, --comment COMMENT | Change the user's GECOS field (full name, office, phone number, etc.) |
-d, --home-dir HOME_DIR | Change the user's home directory to HOME_DIR |
-e, --expiredate EXPIRE_DATE | Set account expiration date (YYYY-MM-DD format) |
-g, --gid GROUP | Change the primary group to GROUP (by name or numeric ID) |
-G, --groups GROUPS | Set supplementary groups (comma-separated list); replaces all groups unless -a is used |
-l, --login NEW_LOGIN | Change the login name from LOGIN to NEW_LOGIN |
-m, --move-home | Move user's home directory to new location (use with -d) |
-s, --shell SHELL | Change the user's login shell to SHELL |
-u, --uid UID | Change the user's UID to UID (must be unique unless -o is used) |
-o, --non-unique | Allow non-unique UID (use with -u) |
-L, --lock | Lock the user account by prefixing password with ! |
Examples
Add user john to the sudo group without removing them from other groups
sudo usermod -a -G sudo johnChange alice's login shell to /bin/bash
sudo usermod -s /bin/bash aliceMove bob's home directory to /home/newhome and update the entry
sudo usermod -d /home/newhome -m bobUpdate the GECOS field (full name) for user john
sudo usermod -c "John Smith, Dept 42" johnChange david's UID to 2000 allowing non-unique UID
sudo usermod -u 2000 -o davidSet account expiration date for tempuser to December 31, 2025
sudo usermod -e 2025-12-31 tempuserRename user oldname to newname
sudo usermod -l newname oldnameLock testuser's account preventing login
sudo usermod -L testuser