RHEL Users, Groups, sudo and Authentication
An account is an operational identity with an owner, purpose, authentication path, authorization and lifecycle. Creating a username is easy; proving who controls it, what it can do, where its actions are recorded and how access is removed is the real work. Shared root passwords and broad sudo rules make incidents faster to cause and harder to attribute.
Separate identity, authentication and authorization
Identity answers which principal is acting. Authentication establishes evidence for that claim. Authorization decides which operation the principal may perform. Local files, SSSD-backed enterprise identity, SSH keys, certificates, PAM and sudo can participate in different layers. A successful SSH login does not imply sudo access, and a sudo rule does not define how the user authenticated.
Human accounts should be individual and attributable. Service accounts need an owner, application purpose, restricted login behavior, protected credentials and retirement date. UID and GID consistency matter for shared filesystems and restored data. Never renumber an active identity without inventorying every file, ACL, process and external mapping that depends on it.
Build the working model
| Layer | Question to answer | Evidence |
|---|---|---|
| Identity | Who or what is acting, and who owns it? | Account record, UID/GID, owner and expiry |
| Authentication | What evidence proves control? | PAM/SSSD/SSH path and successful/failed logs |
| Authorization | Which exact operations are allowed? | Groups, ACLs, sudo command and policy context |
| Session | What environment and credentials exist during action? | TTY/session, sudo log, agent and token scope |
| Lifecycle | How is access reviewed, disabled and removed? | Approval, last use, dependency inventory and revocation evidence |
Implementation sequence
- Classify the identity. Record whether it is human, service, break-glass or external, plus owner and expiry.
- Choose the authoritative source. Avoid creating a local shadow identity when enterprise authentication owns the namespace.
- Allocate groups by function. Grant access to a role group instead of changing every file or issuing shared credentials.
- Write the narrow sudo rule. Match exact commands and arguments where practical; avoid shell escapes and writable command paths.
- Validate before activation. Use
visudo -cf, keep a root console and test both permitted and denied operations in a second session. - Review and retire. Disable access first when appropriate, inventory owned state and scheduled work, then remove under an approved retention decision.
Commands and expected evidence
getent passwd laboperator
getent group webops
id laboperator
useradd --create-home --shell /bin/bash laboperator
groupadd webops
usermod --append --groups webops laboperator
passwd --status laboperator
chage --list laboperator
sudo -l -U laboperator
visudo -cf /etc/sudoers
sssctl user-checks laboperator 2>/dev/null || true
lastlog -u laboperator
journalctl _COMM=sudo --since today --no-pagergetentqueries configured identity sources, while reading/etc/passwdalone shows only local records.usermod --append --groupspreserves existing supplementary groups. Omitting--appendcan remove unrelated access.visudo -cfvalidates syntax but cannot prove the rule grants only the intended semantic capability. Review the called command and writable inputs.sudo -l -Uhelps inspect policy. Test in the real session context because host, group, authentication and included policy can change the result.
Evidence and acceptance criteria
| Evidence | Healthy result | Failure meaning |
|---|---|---|
| Identity source | One authoritative record with expected UID/GID | Local/enterprise collision or stale duplicate |
| Group membership | Only approved functional groups are effective | Privilege accumulation or accidental group removal |
| sudo policy | Syntax passes and allowed/denied tests match the decision | Broad command, escape path or include-order problem |
| Authentication log | Expected success and deliberate failure are attributable | Wrong PAM/SSSD path, clock problem or hidden fallback |
| Lifecycle record | Owner, review date, expiry and retirement dependencies exist | Orphaned persistent access |
Worked scenario: a narrow sudo command still grants a shell
An operations group is permitted to run a text editor as root so members can change one configuration file. The command looks narrow, but the editor can open other files and launch a shell. The rule therefore grants general root capability while the access record describes it as application-only.
The team replaces the editor rule with a controlled deployment command that accepts one reviewed file from a protected staging directory, validates its ownership and syntax, installs it with fixed mode, records the digest and reloads the exact service. The operator can perform the required task without an unrestricted editor or shell.
Practical how-to cases
Case 1: Create a named administrator
Create a local account with a private home and scoped administration membership.
sudo useradd -m -s /bin/bash operator1
sudo passwd operator1
sudo usermod -aG wheel operator1
id operator1
sudo -l -U operator1
getent passwd operator1| Checkpoint | What to establish |
|---|---|
| Expected result | The account has a unique UID, home, valid shell and only intended supplementary groups; sudo policy is visible. |
| If it fails | Missing supplementary membership often requires a new login; duplicate identity requires stopping and reconciling NSS sources. |
| Safe recovery | Lock the account with usermod -L while investigating; delete only after data and process ownership are reassigned. |
Case 2: Create a scoped sudo rule
Allow service status and restart without granting an unrestricted shell.
printf '%%webops ALL=(root) /usr/bin/systemctl status httpd.service, /usr/bin/systemctl restart httpd.service\n' | sudo tee /etc/sudoers.d/webops-httpd
sudo chmod 440 /etc/sudoers.d/webops-httpd
sudo visudo -cf /etc/sudoers.d/webops-httpd
sudo -l -U operator1| Checkpoint | What to establish |
|---|---|
| Expected result | visudo reports parsed OK and the account sees only the reviewed commands. |
| If it fails | Wildcards, editors, shell escapes or broad command arguments can turn a scoped rule into root access. |
| Safe recovery | Keep an existing root session, remove the exact drop-in if validation fails, and retest both permitted and denied commands. |
Case 3: Apply password aging
Set policy on one lab user and distinguish account expiry from password expiry.
sudo chage -M 90 -m 1 -W 14 operator1
sudo chage -l operator1
sudo passwd -S operator1
sudo faillock --user operator1| Checkpoint | What to establish |
|---|---|
| Expected result | The dates reflect the intended maximum, minimum and warning periods; current lock state is understood. |
| If it fails | Unexpected dates can reflect last-change metadata or an already expired password. |
| Safe recovery | Use a controlled password reset or chage -d decision; do not weaken global policy to fix one account. |
Case 4: Retire an account safely
Lock access first, find owned resources, stop scheduled work and only then decide retention.
sudo usermod -L -s /sbin/nologin operator1
sudo pkill -u operator1 2>/dev/null || true
sudo find / -xdev -user operator1 -ls 2>/dev/null
sudo crontab -u operator1 -l 2>/dev/null || true
lastlog -u operator1| Checkpoint | What to establish |
|---|---|
| Expected result | Interactive access is blocked and every owned file, process and scheduled task has a named disposition. |
| If it fails | Deleting first leaves numeric ownership and can remove the only useful home copy. |
| Safe recovery | Unlock only with authorization; otherwise archive required data, reassign ownership and document deletion. |
Independent practice tasks
- Create a service account with no interactive shell and a controlled data directory.
- Configure a sudo rule for one maintenance script, then prove unrelated commands are denied.
- Set and verify account expiry, password expiry and a temporary lock as three separate controls.
- Retire a lab user while preserving a manifest of owned files and scheduled jobs.
For this lesson on RHEL Identity and sudo Administration, complete each task without copying the worked command sequence. Record the initial state, exact change, verification, negative test and recovery command. A task is unfinished if it works now but does not survive a reboot where persistence is required.
Troubleshooting by symptom
| Symptom | Inspect first | Defensible next action |
|---|---|---|
| User exists but login fails | Authoritative source, expiry, shell, PAM/SSSD and SSH logs | Correct the owning identity or authentication layer |
| New group access is absent | Effective session groups and login/session age | Start a new authenticated session after verifying membership |
| sudo rule appears ignored | Include order, host/user/runas/command match and syntax | Inspect sudo -l; correct the exact mismatch |
| Service loses file access after restore | Numeric UID/GID, ACLs, labels and restored ownership | Reconcile identity mapping before broad recursive ownership |
| Account removal breaks automation | Timers, cron, services, files, keys and external ownership | Transfer dependencies before retirement |
Unsafe operations and recovery boundaries
- Unsafe:
ALL=(ALL) NOPASSWD: ALLgives broad unattributed privilege and removes an authentication control. Use the smallest reviewed command set and central session controls. - Unsafe: deleting an account before inventorying processes, files, scheduled jobs and encryption ownership can orphan services or data.
- Unsafe: editing PAM, SSSD, sudo or SSH remotely without console access and a retained privileged session can lock out every administrator.
Rewritten knowledge checks
Guided lab and acceptance test
- Create two lab users and one functional group, then record numeric and resolved identity evidence.
- Give the group access to a lab directory using setgid and a default ACL; verify intended and denied access.
- Create a sudoers drop-in allowing one harmless root-owned wrapper with fixed arguments. Validate it with
visudo -cf. - Test the allowed command, a changed argument and an unrelated command from a new session.
- Lock one lab account and prove how login and existing sessions behave without deleting its files.
- Remove the lab identities only after inventorying their files, processes and scheduled work.