Linux User and Group Management Commands: The Complete 2027 Guide
sudo, and it does not support every advanced sudoers directive. systemd 256 and newer include run0 as a sudo alternative. Account lockout is handled by faillock, which replaced the older pam_tally2 module on current distributions. The core commands in this guide (useradd, usermod, passwd, chage and friends) are stable, but admin group names and defaults still differ between Debian-family and Red Hat-family systems.
Every Linux server you manage starts with the same question: who is allowed to do what? User and group management is the foundation of access control, auditing and least privilege.
This guide covers the commands you need to create, modify, lock and delete accounts, manage groups, control password aging, grant administrative rights safely and audit who is logged in. Each section includes working examples, the files involved, the differences between Ubuntu or Debian and RHEL-family systems, and the mistakes that most often cause outages or security gaps. Use it as a tutorial the first time and as a reference after that.
⚡ Quick Summary
- Create:
sudo useradd -m -s /bin/bash -G devs alice, thensudo passwd alice. On Debian and Ubuntu,adduseris a friendlier interactive wrapper. - Modify: use
usermod -aG group userto add a group. Forgetting the-areplaces all supplementary groups. - Delete:
sudo userdel -r userremoves the account and home directory. Check for running processes and orphaned files first. - Passwords:
passwdsets or locks them, andchagecontrols aging and account expiry. - Admin rights: add users to
sudo(Debian, Ubuntu) orwheel(RHEL family), and edit sudoers only withvisudo. - Audit:
id,getent,last,lastlogandfaillocktell you who exists, who logged in and who is locked out.
- Core concepts and the files behind them
- Inspect users and groups
- Create users: useradd and adduser
- Modify users: usermod
- Delete users: userdel
- Passwords, aging and locking
- Manage groups
- sudo, wheel and privilege escalation
- Failed logins and faillock
- Audit and monitor accounts
- Bulk and automated user management
- Debian family vs Red Hat family
- Troubleshooting common errors
- Best practices checklist
- Command cheat sheet
- FAQ
- Sources
Core concepts and the files behind them
Linux identifies every account by a numeric UID and every group by a numeric GID. Names are labels for those numbers. Each user has one primary group (recorded in /etc/passwd) and any number of supplementary groups (recorded in /etc/group).
| UID range | Typical use |
|---|---|
0 | root, the superuser |
1 to 999 | System accounts for services and daemons (the exact boundary is defined in /etc/login.defs) |
1000 and above | Regular human users on most current distributions |
65534 | nobody, an unprivileged placeholder account |
The key files
| File | What it stores | Who can read it |
|---|---|---|
/etc/passwd | Account name, UID, GID, comment, home directory, login shell | Everyone |
/etc/shadow | Password hashes and aging information | root only |
/etc/group | Group names, GIDs and members | Everyone |
/etc/gshadow | Group passwords and group administrators | root only |
/etc/login.defs | Defaults such as UID ranges, password aging, home directory mode | Everyone |
/etc/default/useradd | Defaults for useradd, shown with useradd -D | Everyone |
/etc/skel | Template files copied into every new home directory | Everyone |
/etc/sudoers and /etc/sudoers.d/ | Who may run which commands with elevated privileges | root only |
Anatomy of an /etc/passwd line
From left to right: login name, password placeholder (the real hash lives in /etc/shadow), UID, primary GID, comment (GECOS) field, home directory and login shell.
vipw and vigr, which lock the files to prevent corruption from simultaneous edits.Inspect users and groups
Start by learning to read the current state. These commands are safe and non-destructive.
# Who am I, and what is my identity?
whoami
id
# Identity of a specific user (UID, primary GID, all groups)
id alice
# Groups a user belongs to
groups alice
# Look up an account or group through all name sources (local files, LDAP, SSSD)
getent passwd alice
getent group devs
# List every regular user (UID 1000 to 65533)
getent passwd | awk -F: '$3 >= 1000 && $3 < 65534 {print $1, $3, $6, $7}'
# List members of a group
getent group sudo
/etc/passwd. getent queries every configured source, while cat /etc/passwd shows only local accounts.Create users: useradd and adduser
useradd: the portable, scriptable tool
useradd exists on every distribution. By default it may not create a home directory unless you pass -m (or CREATE_HOME yes is set in /etc/login.defs), so be explicit.
| Option | Purpose |
|---|---|
-m | Create the home directory and copy files from /etc/skel |
-d /path | Set a custom home directory |
-s /bin/bash | Set the login shell |
-c "Full Name" | Set the comment (GECOS) field |
-g group | Set the primary group (name or GID) |
-G g1,g2 | Set supplementary groups (comma-separated, no spaces) |
-u 1500 | Set a specific UID |
-e YYYY-MM-DD | Set an account expiry date |
-r | Create a system account (low UID, usually no home) |
-D | Show or change the defaults |
# A normal user with home, shell, comment and supplementary groups
sudo useradd -m -s /bin/bash -c "Alice Smith" -G devs,docker alice
# Set the initial password (prompts twice)
sudo passwd alice
# Force a password change at first login
sudo chage -d 0 alice
# A system account for a service: no login shell, no home directory
sudo useradd -r -s /usr/sbin/nologin -c "App service account" appsvc
# A user with an account expiry date (contractor)
sudo useradd -m -e 2027-03-31 -c "Contractor" vendor1
# Show the defaults used by useradd
useradd -D
nologin lives at /sbin/nologin and on others at /usr/sbin/nologin. Run command -v nologin to confirm.adduser: the friendly Debian and Ubuntu wrapper
On Debian and Ubuntu, adduser is a Perl script that asks for a password and personal details, creates the home directory by default and follows distribution policy. On Red Hat-family systems, adduser is simply another name for useradd.
# Debian / Ubuntu: interactive
sudo adduser alice
# Add an existing user to an existing group (Debian family)
sudo adduser alice devs
# System user without a login (Debian family)
sudo adduser --system --group --no-create-home appsvc
Modify users: usermod
usermod changes an existing account. The most dangerous mistake in this whole guide lives here.
usermod -G docker alice replaces all of alice’s supplementary groups with only docker. If she was in sudo or wheel, she just lost admin rights. Use -aG (append) unless you truly want a full replacement.# Append a supplementary group (safe)
sudo usermod -aG docker alice
# Replace the whole supplementary group list (careful)
sudo usermod -G devs,docker alice
# Change the login shell (or let users run chsh themselves)
sudo usermod -s /bin/zsh alice
# Change the primary group
sudo usermod -g devs alice
# Rename the login (home directory and group are NOT renamed automatically)
sudo usermod -l alicia alice
# Rename the login, move the home directory and rename the primary group
sudo usermod -l alicia -d /home/alicia -m alice
sudo groupmod -n alicia alice
# Set or remove an account expiry date
sudo usermod -e 2027-06-30 alice
sudo usermod -e "" alice
# Lock and unlock the password
sudo usermod -L alice
sudo usermod -U alice
newgrp groupname, before the change takes effect.Delete users: userdel
# Remove the account only (home directory and files remain)
sudo userdel alice
# Remove the account, home directory and mail spool
sudo userdel -r alice
# Debian family alternative
sudo deluser --remove-home alice
# Remove the user and back up the home directory first
sudo tar czf /backup/alice-home-$(date +%F).tgz /home/alice
sudo userdel -r alice
Before you delete
- Check for running processes with
ps -u aliceand stop or reassign them.userdelwill refuse if the user is logged in. - Back up the home directory if the data might be needed for compliance, handover or investigation.
- Check cron jobs, services and mail owned by the user:
sudo crontab -l -u alice. - Delete the account with
userdel -r. - Find orphaned files that still carry the old UID and reassign or remove them.
# Find files that no longer belong to any user or group
sudo find / -xdev \( -nouser -o -nogroup \) -ls 2>/dev/null
# Reassign files from an old UID to a new owner
sudo find /srv -xdev -uid 1001 -exec chown newowner {} +
Passwords, aging and locking
passwd
# Change your own password
passwd
# Set another user's password (root)
sudo passwd alice
# Show password status (L = locked, P = usable, NP = no password)
sudo passwd -S alice
# Lock and unlock the password
sudo passwd -l alice
sudo passwd -u alice
# Expire the password now, forcing a change at next login
sudo passwd -e alice
chage: password aging and account expiry
# Show aging information
sudo chage -l alice
# Require a change every 90 days, minimum 1 day between changes, warn 7 days before
sudo chage -M 90 -m 1 -W 7 alice
# Disable the account 14 days after the password expires
sudo chage -I 14 alice
# Set an absolute account expiry date
sudo chage -E 2027-03-31 alice
# Force a password change at next login
sudo chage -d 0 alice
Which lock should you use?
There are several ways to stop an account from working, and they are not equivalent.
| Method | What it blocks | What it does not block |
|---|---|---|
passwd -l or usermod -L | Password logins | SSH public-key logins and existing sessions, in typical configurations |
usermod -e 1 (or chage -E 0) | All logins, because the account is expired, including key-based logins on systems using PAM account checks | Processes already running |
Set shell to nologin | Interactive shells and most remote logins | Some non-shell services, and scheduled jobs |
Remove authorized_keys | Key-based SSH | Password logins |
# A thorough "offboard now" sequence
sudo usermod -L -e 1 -s /usr/sbin/nologin alice
sudo pkill -KILL -u alice # end running sessions and processes
sudo mv /home/alice/.ssh/authorized_keys /home/alice/.ssh/authorized_keys.disabled
pam_pwquality (configured in /etc/security/pwquality.conf), and aging defaults for new users come from /etc/login.defs. See the SSH key guide on VMoreCloud for moving away from passwords entirely. Manage groups
# Create a group (optionally with a fixed GID)
sudo groupadd devs
sudo groupadd -g 2000 finance
# Create a system group
sudo groupadd -r appsvc
# Rename or renumber a group
sudo groupmod -n engineers devs
sudo groupmod -g 2100 engineers
# Delete a group (it cannot be the primary group of any user)
sudo groupdel engineers
# Add and remove members with gpasswd
sudo gpasswd -a alice devs
sudo gpasswd -d alice devs
# Set the exact member list
sudo gpasswd -M alice,bob,carol devs
# Delegate: make bob a group administrator who can manage members
sudo gpasswd -A bob devs
# Start a subshell with a different primary group
newgrp devs
A practical example: a shared project directory
Groups work best combined with directory permissions. The setgid bit makes new files inherit the directory’s group, so everyone on the team can collaborate.
sudo groupadd projectx
sudo mkdir -p /srv/projectx
sudo chown root:projectx /srv/projectx
sudo chmod 2770 /srv/projectx # setgid + rwx for owner and group, nothing for others
sudo usermod -aG projectx alice
sudo usermod -aG projectx bob
ls -ld /srv/projectx # drwxrws--- root projectx
sudo, wheel and privilege escalation
Granting admin rights
The administrative group differs by distribution family:
| Family | Admin group | Grant admin rights |
|---|---|---|
| Debian, Ubuntu | sudo | sudo usermod -aG sudo alice |
| RHEL, Rocky, AlmaLinux, Fedora | wheel | sudo usermod -aG wheel alice |
Editing sudoers safely
Always edit sudoers with visudo, which checks syntax before saving. A broken sudoers file can lock you out of all administrative access.
# Edit the main file safely
sudo visudo
# Preferred: a drop-in file per purpose (keeps changes isolated and auditable)
sudo visudo -f /etc/sudoers.d/90-deploy
# Validate all sudoers files
sudo visudo -c
# /etc/sudoers.d/90-deploy
# Allow the "deploy" user to restart one service without a password
deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart myapp.service
# Allow the "devs" group to run package updates only
%devs ALL=(root) /usr/bin/apt update, /usr/bin/apt upgrade
# Check the files have safe permissions
ls -l /etc/sudoers.d/ # should be -r--r----- (0440), owned by root
# See what a user may run
sudo -l -U alice
ALL=(ALL) NOPASSWD: ALL. If you must allow passwordless commands, name the exact command with its full path. Allowing a command that can launch a shell or edit files is equivalent to full root.What changed in 2027: sudo-rs and run0
- sudo-rs on Ubuntu. Ubuntu 25.10 and the 26.04 LTS ship sudo-rs, a memory-safe Rust reimplementation, as the default
sudo. It is designed as a near drop-in replacement, but it deliberately implements a subset of sudoers features, so some advanced directives are not supported. Reports indicate Canonical plans to drop the original sudo fallback in Ubuntu 26.10, so validate your rules now. - Debian packages sudo-rs but, at the time of writing, does not make it the default.
- run0. systemd 256 and newer include
run0, which elevates privileges without a setuid binary. It works on current Fedora, Arch and Ubuntu releases that carry a recent systemd.
# Which sudo do I have?
sudo --version
update-alternatives --list sudo 2>/dev/null # Ubuntu: shows both implementations if installed
# Validate every sudoers file after an upgrade or migration
sudo visudo -c
# systemd's alternative (systemd 256+)
run0 systemctl restart nginx
/etc/sudoers and /etc/sudoers.d/* into a test machine and run visudo -c and your real commands. Complex rules using less common directives are where differences show up.su and the root account
su - alice # become alice with her environment (needs her password, or root)
sudo -i # root login shell via sudo
sudo -u appsvc whoami # run one command as another user
# Many servers lock the root password and require sudo
sudo passwd -l root
grep -i PermitRootLogin /etc/ssh/sshd_config
Failed logins and faillock
Repeated failed logins can lock an account. On current Red Hat-family systems, and many modern distributions, this is handled by pam_faillock. The older pam_tally2 module has been removed from current distributions. If a tutorial tells you to run pam_tally2 and the command is missing, use faillock.
# Show failed login records for a user
sudo faillock --user alice
# Unlock the user by clearing the failures
sudo faillock --user alice --reset
# Show records for all users
sudo faillock
# /etc/security/faillock.conf (typical settings)
deny = 5 # lock after 5 failed attempts
unlock_time = 900 # unlock automatically after 15 minutes
fail_interval = 900 # window in which failures are counted
faillock command is part of that reset procedure. See our vCenter root password guide. Audit and monitor accounts
# Who is logged in right now, and what are they running?
who
w
# Login history (most recent first), and failed attempts
last -n 20
sudo lastb -n 20
# When did each account last log in?
lastlog | head
# Accounts that have never logged in
lastlog | awk 'NR>1 && /Never logged in/ {print $1}'
# Any account other than root with UID 0 is a red flag
awk -F: '$3==0 {print $1}' /etc/passwd
# Accounts with an empty password field (run as root)
sudo awk -F: '$2=="" {print $1}' /etc/shadow
# Users with a login shell
grep -v -E 'nologin|false' /etc/passwd
# Check the integrity of the account files
sudo pwck -r
sudo grpck -r
# Review sudo usage (systemd journal) or the auth log
sudo journalctl _COMM=sudo --since "1 day ago"
sudo grep sudo /var/log/auth.log # Debian, Ubuntu
sudo grep sudo /var/log/secure # RHEL family
sudo or wheel group. These are classic signs of compromise or sloppy provisioning.Bulk and automated user management
chpasswd and newusers
# Set passwords from a list (user:password per line). Handle this file securely.
sudo chpasswd < passwords.txt
# Create many users from a file (same format as /etc/passwd, with plain passwords)
sudo newusers users.txt
A safe loop for creating team members
#!/usr/bin/env bash
set -euo pipefail
group="devs"
getent group "$group" >/dev/null || groupadd "$group"
while read -r user fullname; do
if id "$user" &>/dev/null; then
echo "skip: $user exists"
continue
fi
useradd -m -s /bin/bash -c "$fullname" -G "$group" "$user"
chage -d 0 "$user" # force password change at first login
echo "created: $user"
done < team.txt # lines like: alice Alice Smith
Configuration management and system accounts
- Ansible: the
ansible.builtin.userandansible.builtin.groupmodules make user management idempotent and auditable. - cloud-init: creates the initial admin user and SSH keys on cloud images.
- systemd-sysusers: declares system accounts for services through files in
/usr/lib/sysusers.d/. Package maintainers use it so service accounts exist predictably. - Central identity: for more than a handful of servers, use LDAP, FreeIPA, or Active Directory through SSSD, so accounts are managed once.
# Example: Ansible ad-hoc to ensure a user exists in the devs group
ansible all -b -m ansible.builtin.user -a "name=alice groups=devs append=yes shell=/bin/bash"
Debian family vs Red Hat family
| Topic | Debian, Ubuntu | RHEL, Rocky, Alma, Fedora |
|---|---|---|
| Admin group | sudo | wheel |
adduser | Interactive wrapper script | Alias for useradd |
| Delete helper | deluser (plus userdel) | userdel |
| Default sudo | sudo (sudo-rs default on Ubuntu 25.10 and 26.04) | sudo |
| Failed login handling | Check your PAM stack and the faillock man page | faillock with /etc/security/faillock.conf |
| Auth log | /var/log/auth.log | /var/log/secure |
| Mandatory access control | AppArmor (Ubuntu) | SELinux. After moving home directories, run restorecon -Rv /home/user |
| Home directory permissions | Check DIR_MODE in /etc/adduser.conf | Check HOME_MODE in /etc/login.defs |
useradd, usermod, userdel and groupadd, which behave consistently, and detect the admin group by checking getent group sudo and getent group wheel.Troubleshooting common errors
| Error or symptom | Cause and fix |
|---|---|
useradd: user 'x' already exists | The name is taken. Check with getent passwd x, including remote sources. |
userdel: user x is currently used by process N | The user is logged in or has running processes. End them with pkill -KILL -u x, or ask the user to log out. |
cannot lock /etc/passwd; try again later | Another tool is editing the file, or a stale lock file such as /etc/passwd.lock remains. Confirm nothing is running, then remove the stale lock. |
alice is not in the sudoers file | Add her to sudo or wheel and have her log in again, or add a rule through visudo. |
| Group added but access still denied | The session has stale group membership. Log out and in, or run newgrp. Check with id. |
groupdel: cannot remove the primary group of user x | Change the user’s primary group with usermod -g first, or delete the user. |
Lost admin rights after usermod -G | The -a flag was missing. Restore the groups with usermod -aG sudo user (or wheel). |
sudo: command not found in a minimal image | Install sudo, or work as root, then add the user to the admin group. |
| Sudoers rule works on one server but not on Ubuntu 26.04 | sudo-rs may not support a directive. Run visudo -c, simplify the rule or check which sudo you run. |
| SSH key login still works for a “locked” user | passwd -l does not block keys. Expire the account with usermod -e 1 or change the shell to nologin. |
| Cannot log in after changing a home directory | Check ownership with ls -ld ~user and on SELinux systems run restorecon -Rv. |
Best practices checklist
- Use individual accounts. No shared logins. Every action should trace to a person.
- Apply least privilege. Give the smallest group or sudo rule that does the job, and prefer named commands over blanket access.
- Manage by groups. Assign permissions to groups, then place people in groups.
- Prefer SSH keys with a passphrase, and disable password SSH logins once keys are in place.
- Set password aging where policy requires it, and use
chageto set expiry for contractors. - Offboard fast and completely: lock, expire, kill sessions, remove keys, review files and cron jobs, then delete after the retention period.
- Review regularly. Audit users, sudo and wheel members, UID 0 accounts and never-used accounts every quarter.
- Keep sudoers in drop-ins under
/etc/sudoers.d/, edited only withvisudo, with change control. - Centralize identity (LDAP, FreeIPA, AD with SSSD) when you manage more than a few hosts.
- Log and alert on sudo use, new users, group changes and repeated failed logins.
- Test changes safely. Keep one root or console session open when changing sudoers or PAM, and take a snapshot or backup before bulk changes.
Command cheat sheet
| Task | Command |
|---|---|
| Create a user with home and shell | sudo useradd -m -s /bin/bash alice |
| Set or change a password | sudo passwd alice |
| Add a user to a group | sudo usermod -aG devs alice |
| Remove a user from a group | sudo gpasswd -d alice devs |
| Change login shell | sudo usermod -s /bin/zsh alice |
| Lock a password | sudo passwd -l alice |
| Expire an account now | sudo usermod -e 1 alice |
| Force a password change at next login | sudo chage -d 0 alice |
| Show password aging | sudo chage -l alice |
| Delete a user and home | sudo userdel -r alice |
| Create a group | sudo groupadd devs |
| Delete a group | sudo groupdel devs |
| Show user identity and groups | id alice |
| Look up users or groups (all sources) | getent passwd alice / getent group devs |
| Grant admin rights (Debian, Ubuntu) | sudo usermod -aG sudo alice |
| Grant admin rights (RHEL family) | sudo usermod -aG wheel alice |
| Edit sudoers safely | sudo visudo |
| Check what a user may run | sudo -l -U alice |
| Unlock failed-login lock | sudo faillock --user alice --reset |
| Recent logins | last -n 20 |
| Failed logins | sudo lastb -n 20 |
| Verify account files | sudo pwck -r && sudo grpck -r |
If you manage Linux alongside Windows Server, Azure and VMware, more practical admin guides are on VMoreCloud.
Frequently asked questions
What is the difference between useradd and adduser?
useradd is the low-level, portable command available on all distributions. adduser on Debian and Ubuntu is an interactive wrapper that creates a home directory and prompts for a password. On Red Hat-family systems, adduser is just another name for useradd.
How do I add a user to a group without removing other groups?
Use sudo usermod -aG groupname username. The -a option appends. Without it, -G replaces all supplementary groups.
How do I give a user sudo access?
Add them to the sudo group on Debian and Ubuntu, or the wheel group on RHEL-family systems, using usermod -aG. For finer control, create a drop-in file under /etc/sudoers.d/ with visudo -f.
How do I disable a user without deleting the account?
Lock the password with passwd -l, and for a complete block also expire the account with usermod -e 1 or set the shell to nologin. A locked password alone does not stop SSH key logins in typical setups.
Why does a new group membership not work immediately?
Running sessions keep the group list they started with. Log out and in again, or use newgrp groupname, and confirm with id.
Is sudo-rs different from sudo?
sudo-rs is a Rust reimplementation designed as a near drop-in replacement. It is the default on Ubuntu 25.10 and 26.04, but it implements a subset of sudoers features, so test advanced rules with visudo -c before upgrading.
Sources and further reading
- Debian manpages: useradd(8)
- Debian manpages: usermod(8)
- Debian manpages: chage(1)
- Debian manpages: gpasswd(1)
- Sudo project: sudoers manual
- sudo-rs project on GitHub
- LinuxConfig: Understanding sudo-rs on Ubuntu 26.04
- systemd: run0 manual
This guide reflects documentation and common administration practice as of October 27, 2026. Command options and defaults can differ between distributions and versions, so check the man pages on your system (man useradd, man sudoers) before running changes in production. Always test account and sudoers changes on a non-production system first and keep a second root session open.

