usermod is the Linux command-line utility that modifies an existing user account by rewriting its records in the system account databases. In the Permissions topic of Linux administration, it is the standard tool for changing group membership, the home directory, the login shell, the user identifier and the account’s locked or expired state without deleting and recreating the user.
Because group membership decides which files, devices and privileged commands a person can reach, usermod is one of the most consequential permission tools on a system. A single mistyped option can silently remove a user from every supplementary group, which is why experienced administrators treat it with the same care as chmod or sudoers edits.
How usermod rewrites account records
usermod works by editing the shadow-utils databases in place: /etc/passwd for the account entry, /etc/shadow for password aging and locking, /etc/group and /etc/gshadow for group membership. It belongs to the shadow-utils package together with useradd, userdel, groupadd and passwd, and it requires root privileges, normally obtained through sudo.
Before writing, the command takes lock files on the databases so that two administrative tools cannot corrupt them at the same moment. It then writes a new copy and renames it over the original, an atomic replacement that leaves either the old or the new version but never a half-written file. Settings such as the valid UID ranges and the mail spool location come from /etc/login.defs.
The following table maps each database to the usermod options that change it.
| File | What it stores | Options that change it |
|---|---|---|
| /etc/passwd | Login name, UID, primary GID, comment, home, shell | -l, -u, -g, -c, -d, -s |
| /etc/shadow | Password hash, aging, expiry, lock marker | -L, -U, -e, -f, -p |
| /etc/group | Group names, GIDs and member lists | -G, -a, -r |
| /etc/gshadow | Group passwords and group administrators | -G, -a, -r |
Key usermod options and what they change
Each option targets one attribute of the account, and several options can be combined in a single invocation. The most frequently used ones are summarized below with their practical effect.
| Option | Effect | Typical use |
|---|---|---|
| -aG group | Appends supplementary groups | Grant access to docker or wheel |
| -G group | Replaces the supplementary group list | Define the exact group set |
| -g group | Changes the primary group | Align new files with a project group |
| -d dir -m | Changes and moves the home directory | Relocate home to another volume |
| -s shell | Changes the login shell | Switch to zsh or disable login |
| -l name | Renames the login | Correct a naming convention |
| -u UID | Changes the user identifier | Harmonize UIDs across servers |
| -L / -U | Locks or unlocks the password | Suspend a departing employee |
| -e date | Sets the account expiry date | Time-limit contractor access |
Newer releases add -r to remove the user from listed groups and -v/-w to manage subordinate UID ranges for rootless containers. Option availability varies by shadow-utils version, so administrators should check the local manual page before scripting.
The append flag and group membership
The single most important rule about usermod is that -G without -a replaces the entire supplementary group list. Running usermod -G docker alice leaves alice in the docker group only, removing her from wheel, audio or any project group she held before. The safe form is usermod -aG docker alice, which appends without removing existing memberships.
Group changes also do not affect running sessions. A process inherits its group list at login, so the user must log out and back in, or start a new shell with newgrp or su -, before the new group appears in the output of id. Long-lived services must be restarted for the same reason.
The difference between the group-related options is easiest to see side by side.
| Command form | Before | After |
|---|---|---|
| usermod -G docker alice | wheel, audio | docker |
| usermod -aG docker alice | wheel, audio | wheel, audio, docker |
| usermod -rG audio alice | wheel, audio | wheel |
| usermod -g dev alice | Primary group alice | Primary group dev |
How usermod differs from neighboring account tools
usermod changes accounts that already exist, while its siblings create, delete or adjust other parts of the identity model. Choosing the right tool avoids side effects such as orphaned files or bypassed policy checks.
| Command | Scope | When to prefer it |
|---|---|---|
| useradd | Creates a new account | Onboarding a new user |
| usermod | Modifies an existing account | Changing groups, shell, home or UID |
| userdel | Removes an account | Offboarding after data handover |
| passwd | Password and its aging | Setting or resetting a password |
| gpasswd | Single group membership | Adding or removing one member |
| chown / chgrp | File ownership | Fixing ownership after a UID change |
Distributions such as Debian also ship adduser and deluser, friendlier wrappers with their own defaults. On systems joined to LDAP, FreeIPA or Active Directory, usermod edits only local files and cannot change directory-managed accounts; those must be changed in the identity service.
Limitations, risks and common mistakes
usermod refuses to change an account with running processes for several options, notably -u, -l and -d -m, because live processes would keep the old identity. Administrators stop the user’s sessions first, or the command fails with a message that the user is currently used by a process.
A UID change rewrites ownership only inside the home directory and the mail spool. Files elsewhere, such as in /srv, /var/www or shared volumes, keep the old numeric owner and appear orphaned until fixed with find / -uid OLD -exec chown. Renaming a login with -l likewise does not rename the home directory or the user’s private group.
- Forgetting -a with -G, which strips every other supplementary group.
- Expecting immediate effect, although group changes apply only to new sessions.
- Locking with -L only, which blocks password login but not SSH key authentication; combine it with an expiry date or a nologin shell.
- Passing a cleartext password to -p, which expects an already hashed value and exposes secrets in shell history.
- Editing directory-managed users locally, which has no effect on centrally managed accounts.
Put simply
Every person who uses a Linux computer has an account. Think of it as a profile card. It says who they are, where their folder lives and which teams they belong to. usermod is the tool an administrator uses to update that profile card without making a new one.
Belonging to a team, called a group, opens doors to shared folders and special abilities. The main rule is simple. usermod must be told to add a team rather than replace all teams. Otherwise the person suddenly loses access to everything else.
In practice
A systems administrator at a mid-sized software company manages a build server shared by twelve developers. A new developer, already in the wheel and dev groups, needs to run containers, so the administrator runs sudo usermod -aG docker mkovac and asks the developer to log out and back in. A quick id mkovac confirms all three groups are present.
Two months later a contractor’s engagement ends. Instead of deleting the account and losing audit history, the administrator runs usermod -L -e 1 -s /usr/sbin/nologin contractor1, which locks the password, expires the account and disables the shell. Because expiry also blocks SSH key logins, access is fully closed while the files remain available for handover.