Users and groups: useradd, usermod
Updated November 1, 2026
useradd creates a user, usermod changes one, groupadd creates a group. These commands need root.
sudo useradd -m alice # create with a home directory (-m)
sudo usermod -aG devs alice # add to the devs group without touching others
id alice # uid, gid, groupsSample output
$ sudo useradd -m alice
$ sudo usermod -aG devs alice
$ id alice
uid=1001(alice) gid=1002(alice) groups=1002(alice),1001(devs)
$ getent passwd alice
alice:x:1001:1002::/home/alice:/bin/sh
$ sudo passwd -S alice
alice L 2026-07-26 0 99999 7 -1How it works: why the -a in usermod -aG
usermod -G devs alicewithout-aREPLACES the supplementary group list with just devs and drops the user from every other group.-ameans append - add to what is already there. This is a common, painful mistake, so almost always write-aG.
Common mistakes
useradd alice without -m writes a line into /etc/passwd and creates no /home/alice. You find out on the first login: su - alice prints su: warning: cannot change directory to /home/alice: No such file or directory and drops you into the root directory. Check getent passwd alice too: the shell there is /bin/sh, because useradd asks nothing and takes the system default. The adduser command on Debian and Ubuntu makes the home directory, gives bash, and asks for a password.
A new user cannot log in with a password until one is set. sudo passwd -S alice prints alice L 2026-07-26 0 99999 7 -1: the L means locked, and /etc/shadow holds a ! where the hash would be. Until you run sudo passwd alice, password login is refused, even though id alice and getent passwd alice show a perfectly normal account.
Adding a group does nothing for the session you are sitting in. Right after sudo usermod -aG devs student, id prints groups=1000(student) while id student already prints groups=1000(student),1001(devs). The kernel hands a process its group list once at login and never revisits it. You need a fresh session: log in again, or run newgrp devs, after which id shows gid=1001(devs) groups=1001(devs),1000(student).
Used in
You need this in the lesson Users and permissions.