Linux Users and Groups — Accounts, sudo, and Password Policy

LINUX-USERS-GROUPS

How Linux manages user identities through the /etc/passwd and /etc/shadow databases, the commands for creating and modifying user accounts, how groups enable shared access to resources, and how sudo grants controlled privilege escalation without sharing the root password.

linuxusersgroupssudopasswd

Overview

Linux access control is built entirely on numeric identifiers: every user has a UID and every file has an owner UID. The kernel does not store usernames internally — it stores numbers. The files in /etc that map those numbers to human-readable names are a convenience layer on top of this numeric foundation. Understanding the structure of those files, the commands that manipulate them, and the mechanisms for controlled privilege escalation gives you a complete picture of how RHEL governs who can do what.


/etc/passwd — User Database

Every user account is a single line in /etc/passwd. The file is readable by all users; the kernel and utilities like ls read it to resolve UIDs to names. Seven colon-separated fields:

username:x:UID:GID:comment:home:shell
student:x:1000:1000:Student User:/home/student:/bin/bash
FieldMeaning
usernameLogin name
xPassword is stored in /etc/shadow (always x on modern systems)
UIDNumeric user identifier
GIDNumeric primary group identifier
commentGECOS field — typically the user’s full name; optional
homeAbsolute path to the user’s home directory
shellLogin shell; /sbin/nologin or /bin/false denies interactive login for service accounts

UID ranges on RHEL define account purpose:

UID RangeAccount Type
0root — superuser
1–200Static system accounts assigned by RPM packages at install time
201–999Dynamic system accounts created for services at install time (useradd -r)
1000+Regular interactive user accounts

/etc/shadow — Password Database

/etc/shadow stores hashed passwords and password aging policy. It is readable only by root. Nine colon-separated fields:

username:hashed_password:lastchange:min:max:warn:inactive:expire:reserved
FieldMeaning
usernameMatches the name in /etc/passwd
hashed_passwordSalted hash; !! = account locked (no valid password); blank = no password required
lastchangeDays since 1970-01-01 when the password was last changed
minMinimum days before the password may be changed again (0 = no minimum)
maxMaximum days the password is valid before forced change (99999 = never expires)
warnDays before expiry when the user is warned
inactiveDays after expiry before the account is locked
expireAbsolute date the account expires (empty = never)

The hash format indicates the algorithm used:

PrefixAlgorithmStatus
$6$SHA-512Current RHEL default — secure
$5$SHA-256Acceptable
$1$MD5Weak — avoid on modern systems

/etc/group — Group Database

Four colon-separated fields:

groupname:x:GID:members
wheel:x:10:student,admin

Every user has a primary group (the GID in /etc/passwd) and may belong to multiple supplementary groups (listed in /etc/group). The id command shows a user’s UID, primary GID, and all group memberships. Files created by a user are owned by that user’s primary group by default.


Creating and Managing User Accounts

useradd

OptionEffect
useradd usernameCreate a user with defaults from /etc/default/useradd
-u UIDAssign a specific UID
-g groupnameSet the primary group
-G g1,g2Add to supplementary groups at creation time
-d /pathSet the home directory path
-s /bin/bashSet the login shell
-c "comment"Set the GECOS comment field
-MDo not create a home directory
-rCreate a system account (UID below 1000, no home directory, no expiry)

Files in /etc/skel are copied into the new user’s home directory when useradd creates it. Placing template configuration files in /etc/skel ensures every new user starts with a consistent baseline.

usermod

OptionEffect
usermod -aG groupname usernameAppend the user to a supplementary group — the -a flag is critical; omitting it replaces all supplementary group memberships
usermod -l newname oldnameRename the account (does not rename home directory)
usermod -d /new/home -m usernameChange home directory and move its contents
usermod -s /bin/zsh usernameChange the login shell
usermod -L usernameLock the account by prepending ! to the shadow hash
usermod -U usernameUnlock the account

userdel

CommandEffect
userdel usernameRemove the account, leaving the home directory intact
userdel -r usernameRemove the account and delete the home directory and mail spool

passwd

CommandEffect
passwdChange your own password
passwd usernameChange another user’s password (root only)
passwd -l usernameLock the account
passwd -u usernameUnlock the account
passwd -e usernameExpire the password immediately — forces a change at the next login

Group Management

CommandEffect
groupadd groupnameCreate a new group with the next available GID
groupadd -g 5000 groupnameCreate a group with a specific GID
groupmod -n newname oldnameRename a group
groupmod -g 6000 groupnameChange a group’s GID
groupdel groupnameDelete a group (fails if it is any user’s primary group)

Switching Users

Two commands switch the active user identity within a session:

su username starts a subshell as the specified user, but keeps the current environment — the working directory, PATH, and environment variables remain those of the original user. This is rarely what you want.

su - username starts a full login shell as the target user: it changes to that user’s home directory, loads their environment variables, and sets PATH appropriately. Always use su - when switching to root:

su -

Without the dash, root’s PATH may not include /sbin and /usr/sbin, causing administrative commands to appear missing.


sudo — Privilege Escalation Without Sharing root

sudo allows specific users to run commands as root (or another user) without knowing the root password. Configuration lives in /etc/sudoers and the drop-in directory /etc/sudoers.d/. Always edit /etc/sudoers with visudo — it performs syntax checking before saving and prevents a malformed file from locking out all sudo access.

sudoers Syntax

user    ALL=(ALL)    ALL
%wheel  ALL=(ALL)    ALL
%wheel  ALL=(ALL)    NOPASSWD: ALL

On RHEL, members of the wheel group have full sudo access by default. Adding a user to wheel with usermod -aG wheel username is the standard way to grant administrative access.

Key sudo Commands

CommandEffect
sudo commandRun command as root
sudo -iOpen an interactive root login shell (equivalent to su - but authenticated via sudo)
sudo -lList the commands the current user is permitted to run via sudo
sudo -u username commandRun command as a specific user other than root

Password Aging with chage

chage (change age) reads and writes the password aging fields in /etc/shadow:

CommandEffect
chage -l usernameList all password aging settings for the user
chage -M 90 usernameSet maximum password age to 90 days
chage -m 7 usernameSet minimum days between password changes to 7
chage -W 14 usernameWarn the user 14 days before the password expires
chage -I 7 usernameLock the account 7 days after password expiry
chage -E 2026-12-31 usernameSet the account expiry date
chage -d 0 usernameForce a password change at the next login (equivalent to passwd -e)

System-wide defaults for new accounts are set in /etc/login.defs:

DirectiveMeaning
PASS_MAX_DAYSMaximum password age for new accounts
PASS_MIN_DAYSMinimum days between password changes for new accounts
PASS_WARN_AGEDays of warning before expiry for new accounts
UID_MINLowest UID assigned to regular users by useradd
SYS_UID_MAXHighest UID assigned to system accounts by useradd -r

Changes to /etc/login.defs apply to accounts created after the change, not to existing accounts. Use chage to update aging policy on existing accounts individually.


Summary

Linux user management centres on three flat-file databases: /etc/passwd maps usernames to UIDs and login shells; /etc/shadow stores password hashes and aging policy; /etc/group maps group names to GIDs and member lists. The useradd, usermod, and userdel commands manipulate these files safely. The wheel group and sudo provide controlled privilege escalation without exposing the root password — the preferred model for all interactive administrative work. Password aging enforced via chage and /etc/login.defs ensures credentials rotate on a defined schedule and that compromised accounts lock automatically after expiry.