The usermod command
The usermod command changes a user account…
The usermod command changes a user account: sudo usermod -aG sudo sam adds sam to the sudo group and keeps the groups sam is already in.
Taught in Advanced, lesson 41
A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.
Usage
sudo usermod -aG GROUP USER sudo usermod [-s SHELL] [-L] [-U] USER
Change a user account. Changes an existing account. The one you will use most is usermod -aG GROUP USER, which adds the user to a group (for example sudo, to make them an administrator). Keep the -a: -G alone replaces all their extra groups with the ones you list. On a real system the change applies the next time that user logs in. Needs sudo. Everything here is simulated in the page: no real accounts, passwords or software are involved.
In the practice terminal:Changes go to the practice machine’s own /etc/passwd and /etc/group, inside the page. Nothing changes on your computer.
How to use usermod
Add a user to a group: usermod -aG
-a (append) matters: -G on its own replaces all of the user’s extra groups with the ones you list. The change applies from the user’s next login.
sudo useradd -m sam && sudo usermod -aG sudo sam && groups sam[sudo] password for learner: sam : sam sudo
Why -G without -a is risky
sam was in adm; after usermod -G sudo it is in sudo alone.
sudo useradd -m -G adm sam && sudo usermod -G sudo sam && groups sam[sudo] password for learner: sam : sam sudo
Change the login shell: usermod -s
sudo usermod -s /bin/zsh learner && grep learner /etc/passwd[sudo] password for learner: learner:x:1000:1000:learner:/home/learner:/bin/zsh
Lock an account: usermod -L
A locked account can’t log in with its password; -U unlocks it. passwd -S shows L for locked.
sudo useradd -m sam && sudo passwd sam && sudo usermod -L sam && sudo passwd -S sam[sudo] password for learner: New password: Retype new password: passwd: password updated successfully sam L 2026-01-12 0 99999 7 -1
Options
| -aG GROUPS | add to these groups, keeping the others |
|---|---|
| -G GROUPS | set the extra groups to exactly these |
| -s SHELL | change the login shell |
| -L, -U | lock or unlock the password |
More examples
sudo usermod -aG adm learner[sudo] password for learner:
Questions about usermod
Why don’t my new groups show up?
Group changes apply when the user logs in again. Log out and back in, and groups then shows the new list.
What is the difference between usermod -G and usermod -aG?
-G sets the full list of extra groups and removes any you leave out. -aG adds to the list, which is almost always what you want.
Can usermod rename a user?
Yes: sudo usermod -l newname oldname. The home folder keeps its old name unless you also move it with -d and -m.
Learn it step by step
Related commands
Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.