Linux User Management: useradd, usermod, and userdel

Managing Linux user accounts from the command line is a core sysadmin skill — the GUI tools most distros offer are fine for a desktop, but servers are managed via these commands almost exclusively.

# Create a new user with a home directory and specific shell
sudo useradd -m -s /bin/bash alice

# Set their password
sudo passwd alice

# Add an existing user to a group (e.g. sudo/wheel, or docker)
sudo usermod -aG sudo alice     # -a is critical - appends, doesn't replace existing groups

# Lock an account without deleting it
sudo usermod -L alice
sudo passwd -l alice            # equivalent

# Delete a user, optionally removing their home directory too
sudo userdel -r alice

# List a user's group memberships
groups alice
id alice

The -a Flag Mistake

Forgetting -aG and using just -G instead REPLACES a user’s existing group memberships entirely rather than adding to them — a classic mistake that silently removes a user from groups they were supposed to keep, often not discovered until something they used to have access to suddenly breaks.