$linuxjunkies
>

usermod(8)

Modify a user account's login name, UID, groups, home directory, shell, and other attributes.

UbuntuDebianFedoraArch

Synopsis

usermod [OPTION]... LOGIN

Description

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

FlagWhat it does
-a, --appendAppend the user to supplementary groups; only use with -G (prevents removing from other groups)
-c, --comment COMMENTChange the user's GECOS field (full name, office, phone number, etc.)
-d, --home-dir HOME_DIRChange the user's home directory to HOME_DIR
-e, --expiredate EXPIRE_DATESet account expiration date (YYYY-MM-DD format)
-g, --gid GROUPChange the primary group to GROUP (by name or numeric ID)
-G, --groups GROUPSSet supplementary groups (comma-separated list); replaces all groups unless -a is used
-l, --login NEW_LOGINChange the login name from LOGIN to NEW_LOGIN
-m, --move-homeMove user's home directory to new location (use with -d)
-s, --shell SHELLChange the user's login shell to SHELL
-u, --uid UIDChange the user's UID to UID (must be unique unless -o is used)
-o, --non-uniqueAllow non-unique UID (use with -u)
-L, --lockLock 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 john

Change alice's login shell to /bin/bash

sudo usermod -s /bin/bash alice

Move bob's home directory to /home/newhome and update the entry

sudo usermod -d /home/newhome -m bob

Update the GECOS field (full name) for user john

sudo usermod -c "John Smith, Dept 42" john

Change david's UID to 2000 allowing non-unique UID

sudo usermod -u 2000 -o david

Set account expiration date for tempuser to December 31, 2025

sudo usermod -e 2025-12-31 tempuser

Rename user oldname to newname

sudo usermod -l newname oldname

Lock testuser's account preventing login

sudo usermod -L testuser

Related commands