usermod
Overview
usermod modifies an existing user account: groups, shell, home, lock state, and more.
Syntax
sudo usermod [options] LOGINCommon Options
| Option | Description |
|---|---|
-aG group,group |
Append supplementary groups |
-G groups |
Set supplementary groups (replaces list!) |
-g group |
Primary group |
-d home -m |
New home and move contents |
-s shell |
Login shell |
-l newname |
Rename login |
-L / -U |
Lock / unlock password |
-e YYYY-MM-DD |
Account expiry |
-u UID |
Change UID (careful with file ownership) |
Safety
-G without -a resets secondary groups to only those listed — easy way to drop someone from sudo. Always prefer -aG to add groups.
Examples with Explanations
Add to sudo / docker
sudo usermod -aG sudo alice
sudo usermod -aG docker alice
# re-login for group membership to apply
id aliceChange shell / home
sudo usermod -s /bin/zsh alice
sudo usermod -d /home/alice2 -m aliceLock / unlock
sudo usermod -L alice
sudo usermod -U alice
sudo passwd -S aliceRename
sudo usermod -l newbob bob
# also rename home if desired with -d -mNotes
- Active sessions keep old groups until re-login (
newgrp/ re-SSH).
- Changing UID leaves old-owned files behind —
find / -user OLDUID.
- Prefer
vipwonly if you know the format;usermodis safer.