Linux user management controls who can access a system, what they can do, and where they can go. For ethical hackers, penetration testers, and system administrators, understanding how users, groups, and privilege levels work is essential — both for hardening systems and for identifying exploitation paths.
In Linux, every action taken on the system is performed by a user. Whether it is a human administrator, a running web server process, or a scheduled cron job — each has an associated user account that determines its permissions across the entire file system. Linux user management is the practice of creating, modifying, monitoring, and securing those accounts to enforce the principle of least privilege.
The three types of Linux users
UID 0: Root user (Superuser)
The all-powerful superuser with unrestricted access to every file, command, and system resource. Direct root login should be disabled on production systems — use sudo instead.
UID 1–999: System users (Service accounts)
Non-human accounts created automatically by the system for running services — www-data for Apache, mysql for databases. They have no login shell and no home directory by design.
UID 1000+: Regular users (Human accounts)
Standard human user accounts with limited privileges scoped to their own home directory and authorized resources. Elevated access is granted explicitly via sudo or group membership.
Every Linux user is identified by a numeric UID (User ID) — not their username. The username is just a human-readable label. Internally, the kernel uses the UID for all permission checks. This is why two accounts with different names but the same UID have identical access rights.
Essential user and group management commands
User management commands
useradd username
Create a new user account — does not set a password or create a home directory by default on some distros
useradd -m -s /bin/bash alice
Create user with a home directory (-m) and bash login shell (-s) — the recommended form
passwd username
Set or change a user’s password — prompts for the new password securely
usermod -aG sudo alice
Add user alice to the sudo group — granting administrative privilege escalation rights
usermod -L alice
Lock a user account — prevents login without deleting the account or its data
userdel -r alice
Delete user and remove their home directory and mail spool (-r flag)
id alice
Display alice’s UID, primary GID, and all group memberships — essential for enumeration
whoami
Print the current user’s username — first command run after gaining shell access
Group management commands
groupadd developers
Create a new group named developers
groupdel developers
Delete a group — users in the group are not deleted, only the group association is removed
groups alice
List all groups that alice belongs to
cat /etc/group
View all groups on the system along with their GIDs and member lists
Understanding /etc/passwd and /etc/shadow
Understanding /etc/passwd and /etc/shadow
/etc/passwd — readable by all users
alice:x:1001:1001:Alice Smith:/home/alice:/bin/bash
username password(x=shadow) UID GID comment home dir shell
/etc/shadow — readable by root only (permission 640)
/etc/shadow — readable by root only (permission 640)
alice:$6$salt$hashedpassword…:19450:0:99999:7::::
username hashed password (SHA-512) last change min age max age warning days
In a penetration test, gaining read access to /etc/shadow is a critical finding. The SHA-512 password hashes stored there can be cracked offline using Hashcat or John the Ripper — especially when users have weak passwords. This file should always be owned by root with permissions 640 or stricter.
User management security best practices
Principle of least privilege: Minimize sudo access
Audit /etc/sudoers regularly. Grant users only the specific commands they need — not blanket ALL=(ALL) ALL access which is equivalent to root.
Account hygiene: Disable unused accounts
Lock or delete accounts for employees who have left, completed projects, or are on extended leave using usermod -L or userdel -r.
Root access: Disable direct root login
Set PermitRootLogin no in /etc/ssh/sshd_config to block direct root SSH access. All privileged actions should go through sudo with full audit logging.
Password policy: Enforce strong passwords
Use PAM (Pluggable Authentication Modules) to enforce minimum password length, complexity, and expiry. Configure /etc/login.defs for system-wide password aging policies.
Enumeration defense: Monitor /etc/passwd changes
Use file integrity monitoring tools like AIDE to detect unauthorized additions to /etc/passwd — a common attacker technique for creating backdoor accounts.
Pen testing context: Enumerate users on target
During post-exploitation, cat /etc/passwd, id, and getent passwd reveal all accounts, their UIDs, and shells — mapping privilege escalation paths on the target.
When a penetration tester gains a low-privilege shell on a Linux target, id and cat /etc/passwd are among the first commands executed. Group memberships revealed by id — particularly membership in sudo, docker, or disk groups — are immediate privilege escalation vectors that can lead to full root access.

