useradd — Create and Manage User Accounts on Linux
Practical guide to useradd, usermod and userdel — create, modify and delete Linux user accounts, home directories, groups and passwords safely.
useradd is the low-level standard tool for creating Linux user accounts directly – without -m it leaves no home directory, and without a follow-up passwd the account stays locked. On Debian and Ubuntu the friendlier adduser wrapper handles those steps interactively and applies sensible defaults. Together with usermod, userdel, passwd and the group commands you manage accounts, shells and group memberships. Almost every one of these actions needs sudo and reaches deep into the system.
Create Users
useradd <user> — Create a new user (minimal, no home directory on some distros).
sudo useradd johnuseradd -m <user> — Create a user with a home directory.
sudo useradd -m johnuseradd -m -s <shell> <user> — Create a user with a specific login shell.
sudo useradd -m -s /bin/bash johnuseradd -m -G <groups> <user> — Create a user and add to supplementary groups.
sudo useradd -m -G sudo,docker johnuseradd -r -s /usr/sbin/nologin <user> — Create a system user (no login, for services).
sudo useradd -r -s /usr/sbin/nologin appuseruseradd -m -c '<comment>' <user> — Create a user with a full name/comment.
sudo useradd -m -c 'John Doe' johnModify Users
usermod -aG <group> <user> — Add a user to a group (append, keep existing groups).
sudo usermod -aG docker johnusermod -s <shell> <user> — Change a user's login shell.
sudo usermod -s /bin/zsh johnusermod -l <newname> <oldname> — Rename a user account.
sudo usermod -l johndoe johnusermod -d <dir> -m <user> — Change home directory and move files.
sudo usermod -d /home/johndoe -m johnusermod -L <user> — Lock a user account (disable login).
sudo usermod -L johnusermod -U <user> — Unlock a user account.
sudo usermod -U johnDelete Users
userdel <user> — Delete a user (keep home directory).
sudo userdel johnuserdel -r <user> — Delete a user and remove home directory.
sudo userdel -r johnPasswords
passwd <user> — Set or change a user's password.
sudo passwd johnpasswd -l <user> — Lock a user's password.
sudo passwd -l johnpasswd -u <user> — Unlock a user's password.
sudo passwd -u johnpasswd -e <user> — Expire password (force change on next login).
sudo passwd -e johnchage -l <user> — Show password aging information.
sudo chage -l johnchage -M <days> <user> — Set maximum password age in days.
sudo chage -M 90 johnGroups
groupadd <group> — Create a new group.
sudo groupadd developersgroupdel <group> — Delete a group.
sudo groupdel developersgroups <user> — Show all groups a user belongs to.
groups johngpasswd -a <user> <group> — Add a user to a group.
sudo gpasswd -a john dockergpasswd -d <user> <group> — Remove a user from a group.
sudo gpasswd -d john dockergetent group <group> — Show members of a group.
getent group dockerInfo & Listing
id <user> — Show user UID, GID, and group memberships.
id johnwhoami — Show the current username.
whoamigetent passwd <user> — Show user account details from passwd database.
getent passwd johncat /etc/passwd | grep <user> — Look up a user in the passwd file.
cat /etc/passwd | grep johnlast <user> — Show last login times for a user.
last john Conclusion
For everyday work a handful of commands suffice: useradd -m creates a full account with a home directory, passwd sets the first password, and usermod -aG appends group memberships. That last one hides the most common trap – forget the -a and usermod -G replaces all existing supplementary groups instead of adding to them. Keep in mind that membership in sudo or docker effectively grants root-equivalent privileges and should be handed out deliberately. And userdel -r wipes the entire home directory along with all its data – without asking.
Further Reading
- Arch Wiki: Users and groups – thorough reference on Linux account and group management
- Debian Wiki: UserManagement – managing users and groups on Debian-based systems