Skip to main content
Kill -9 Club
Sign in

usermod

AccountsPackage: passwdHandle with care

Changes an existing account: its groups, its shell, its expiry, its lock. The options look alike and do not do the same thing — -G replaces the group list, -aG adds to it.

A mistake with this command can destroy data or lock you out

  • usermod -G without -a replaces every secondary group of the account with the ones you list. On an admin account, that is how you lose sudo while trying to add yourself to docker.

What its options do in the lessons

From the same glossary the lessons render under their commands, so the two cannot disagree.

usermod -a
Appends to the listed groups instead of replacing the list. Only valid with -G — forgetting it removes the user from every other group.
usermod -G
The supplementary groups. On its own it *replaces* the list; with -a it adds to it.
usermod --lock
Locks the password by prefixing it with !: no password login remains, without deleting the account or its files.
usermod --expiredate
The date the account is disabled. --expiredate 1 disables it immediately.
usermod --unlock
Removes the ! in front of the hash, so the previous password works again. If there is nothing behind the !, the command refuses rather than leave a passwordless account.

Lessons that teach it