Local Account Administration and Password Policies
CIS126RH | RHEL System Administration 1 Mesa Community College
Learning Objectives
1
Obtain superuser access
Use su and sudo to run commands with elevated privileges
2
Create and manage local users
Add, modify, and delete user accounts with useradd, usermod, userdel
3
Manage local groups
Create groups and manage memberships with groupadd, groupmod, gpasswd
4
Administer password policies
Configure password aging and account expiration with chage
The Root User
root (UID 0) is the superuser account with unrestricted access to the entire system. Root can read any file, modify any setting, and execute any command.
Root Can:
Read/write any file on the system
Install and remove software
Manage all users and groups
Configure network and services
Mount filesystems
Change ownership and permissions
Dangers of Root:
Typos can be catastrophic
No confirmation for destructive actions
Malware runs with full privileges
Hard to audit who did what
Accidents affect entire system
No "undo" for many operations
Best Practice: Never log in directly as root. Use sudo for individual commands instead.
Switching Users: su
# Switch to root (prompts for root password)[student@server ~]$ su
Password: [enter root password][root@server student]## Switch to root with login environment (recommended)[student@server ~]$ su -
Password:
[root@server ~]## Switch to another user[student@server ~]$ su - jsmith
Password: [enter jsmith's password][jsmith@server ~]$# Run single command as another user[student@server ~]$ su -c "whoami" jsmith
Password:
jsmith# Exit back to original user[root@server ~]# exit
[student@server ~]$
su vs su -: The dash (-) creates a login shell with the target user's environment. Without it, you keep your current environment variables.
Elevated Privileges: sudo
sudo (superuser do) runs a single command with elevated privileges. Users authenticate with their own password and must be authorized in the sudoers configuration.
# Run command as root[student@server ~]$ sudo systemctl restart httpd
[sudo] password for student: [enter YOUR password]# View who you become with sudo[student@server ~]$ sudo whoami
root# Run command as specific user[student@server ~]$ sudo -u apache cat /etc/httpd/conf/httpd.conf
# Open root shell (use sparingly)[student@server ~]$ sudo -i
[root@server ~]## List your sudo privileges[student@server ~]$ sudo -l
sudo Configuration
# Edit sudoers safely (ALWAYS use visudo!)[root@server ~]# visudo
# sudoers file syntax examples:# User privilege specification
student ALL=(ALL) ALL # Full sudo access# Allow without password
operator ALL=(ALL) NOPASSWD: ALL
# Limit to specific commands
backup ALL=(ALL) /usr/bin/rsync, /usr/bin/tar
# Group-based access (note the %)
%wheel ALL=(ALL) ALL # Members of wheel group
%admins ALL=(ALL) NOPASSWD: /usr/bin/systemctl
# Drop-in files (recommended method)[root@server ~]# cat /etc/sudoers.d/student
student ALL=(ALL) ALL
⚠ Always use visudo! It validates syntax before saving. A broken sudoers file can lock you out of sudo entirely.
The wheel Group
On RHEL, the wheel group grants sudo access to its members. This is the standard way to allow users administrative privileges.
# Add user to wheel group for sudo access[root@server ~]# usermod -aG wheel student
# Verify membership[student@server ~]$ groups
student wheel# Check the sudoers configuration[root@server ~]# grep wheel /etc/sudoers
%wheel ALL=(ALL) ALL# Group must be effective - logout/login or use newgrp[student@server ~]$ newgrp wheel
# Now sudo should work[student@server ~]$ sudo whoami
root
RHCSA Tip: Adding a user to the wheel group is the standard way to grant administrative access on RHEL systems.
User Account Files
File
Purpose
Permissions
/etc/passwd
User account information
644 (world-readable)
/etc/shadow
Encrypted passwords, aging
000 (root only)
/etc/group
Group definitions
644 (world-readable)
/etc/gshadow
Group passwords (rarely used)
000 (root only)
/etc/login.defs
Default settings for useradd
644
/etc/default/useradd
Additional useradd defaults
644
Never edit these files directly! Use the provided commands (useradd, usermod, passwd, etc.) to ensure consistency and proper locking.
# View specific user's entry
grep student /etc/passwd
student:x:1000:1000:Student User:/home/student:/bin/bash
UID Ranges
System Accounts
0 - 999
root (0), bin, daemon, apache, nobody, etc.
Regular Users
1000 - 60000
Normal user accounts First user typically gets 1000
# Check UID range configuration
grep -E "^UID_MIN|^UID_MAX|^SYS_UID" /etc/login.defs
UID_MIN 1000
UID_MAX 60000
SYS_UID_MIN 201
SYS_UID_MAX 999# Create system user (UID below 1000)
useradd -r -s /sbin/nologin myservice
# View result
id myservice
uid=987(myservice) gid=984(myservice) groups=984(myservice)
Creating Users: useradd
# Create user with defaults[root@server ~]# useradd jsmith
# Create user with options[root@server ~]# useradd -c "John Smith" -s /bin/bash -m -d /home/jsmith jsmith
# Common options:
useradd -u 1500 username # Specify UID
useradd -g developers username # Specify primary group
useradd -G wheel,dev username # Add to supplementary groups
useradd -s /sbin/nologin svc # No interactive login
useradd -e 2025-12-31 temp # Account expiration date
useradd -r serviceacct # Create system user# View what useradd would do without creating
useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
Setting Passwords
# Set/change password interactively[root@server ~]# passwd jsmith
Changing password for user jsmith.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.# User changes their own password[jsmith@server ~]$ passwd
Changing password for user jsmith.
Current password:
New password:
# Set password non-interactively (scripts)[root@server ~]# echo "newpassword" | passwd --stdin jsmith
# Force password change at next login[root@server ~]# passwd -e jsmith
Expiring password for user jsmith.# Lock an account[root@server ~]# passwd -l jsmith # Lock[root@server ~]# passwd -u jsmith # Unlock
⚠ Security Note: The --stdin method puts passwords in shell history and process listings. Use carefully!
CRITICAL: Always use -aG together when adding groups! Using -G alone removes all other supplementary groups!
Deleting Users: userdel
# Delete user (keeps home directory)[root@server ~]# userdel jsmith
# Delete user AND home directory[root@server ~]# userdel -r jsmith
# Force delete even if user is logged in[root@server ~]# userdel -f jsmith
# Check for files owned by deleted user's UID[root@server ~]# find / -nouser 2>/dev/null
# Before deleting, check what they own[root@server ~]# find / -user jsmith 2>/dev/null
Without -r:
Home directory remains
Mail spool remains
Files become orphaned (owned by UID)
With -r:
Removes home directory
Removes mail spool
Other files still orphaned
Managing Groups
# Create a new group[root@server ~]# groupadd developers
# Create group with specific GID[root@server ~]# groupadd -g 5000 webteam
# Create system group[root@server ~]# groupadd -r appgroup
# Modify group - change name[root@server ~]# groupmod -n devteam developers
# Modify group - change GID[root@server ~]# groupmod -g 6000 devteam
# Delete a group[root@server ~]# groupdel devteam
# View group information[root@server ~]# getent group developers
developers:x:5001:jsmith,ajones# View a user's groups[student@server ~]$ groups
student wheel developers
Group Membership
# Add user to group (preferred method)[root@server ~]# usermod -aG developers jsmith
# Add user to group using gpasswd[root@server ~]# gpasswd -a jsmith developers
Adding user jsmith to group developers# Remove user from group[root@server ~]# gpasswd -d jsmith developers
Removing user jsmith from group developers# Set group administrators[root@server ~]# gpasswd -A jsmith developers
# List group members[root@server ~]# getent group developers
developers:x:5001:jsmith,ajones,bwilson# Alternative: use lid to show user's groups[root@server ~]# lid -g developers
jsmith(uid=1000)
ajones(uid=1001)
Primary vs Supplementary: Users have ONE primary group (for new files) and can have MULTIPLE supplementary groups (for access).
Understanding /etc/shadow
jsmith:$6$xyz...:19500:0:99999:7:::
Field
Name
Description
1
Username
Login name
2
Password Hash
Encrypted password (!! = no password, ! = locked)
3
Last Change
Days since Jan 1, 1970 of last password change
4
Minimum Age
Days before password CAN be changed
5
Maximum Age
Days before password MUST be changed
6
Warning Period
Days of warning before expiration
7
Inactive Period
Days after expiration before account locks
8
Expiration Date
Days since epoch when account expires
Password Aging: chage
# View current aging settings[root@server ~]# chage -l jsmith
Last password change : Dec 01, 2025
Password expires : Mar 01, 2026
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 90
Number of days of warning before password expires : 7# Set maximum password age (90 days)[root@server ~]# chage -M 90 jsmith
# Set minimum age (1 day - prevents immediate changes)[root@server ~]# chage -m 1 jsmith
# Set warning days (14 days before expiration)[root@server ~]# chage -W 14 jsmith
# Set inactive period (30 days after expiration)[root@server ~]# chage -I 30 jsmith
# Force password change at next login[root@server ~]# chage -d 0 jsmith
Account Expiration
# Set account expiration date[root@server ~]# chage -E 2025-12-31 contractor
# Alternative: use usermod[root@server ~]# usermod -e 2025-12-31 contractor
# Remove account expiration (never expires)[root@server ~]# chage -E -1 contractor
# Interactive mode - prompts for all values[root@server ~]# chage contractor
Changing the aging information for contractor
Enter the new value, or press ENTER for the default
Minimum Password Age [0]: 1
Maximum Password Age [99999]: 90
...# Verify account status[root@server ~]# chage -l contractor | grep "Account expires"
Account expires : Dec 31, 2025
Use Case: Account expiration is perfect for contractors, interns, and temporary employees - set it when creating the account and it auto-disables.
Default Policies
# View/edit system-wide defaults[root@server ~]# cat /etc/login.defs | grep PASS
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7# Edit to set organization policy[root@server ~]# vim /etc/login.defs
# Change to:
PASS_MAX_DAYS 90
PASS_MIN_DAYS 1
PASS_MIN_LEN 12
PASS_WARN_AGE 14
# These defaults apply to NEW users only!# Existing users keep their current settings# Apply policy to existing user[root@server ~]# chage -M 90 -m 1 -W 14 existinguser
⚠ Important: Changes to /etc/login.defs only affect newly created users. Use chage to update existing accounts.
Key Takeaways
1
Superuser access: Use sudo for individual commands, avoid logging in as root. Add users to wheel group.
2
User management:useradd, usermod, userdel, passwd - set passwords after creating users!
3
Groups:groupadd, usermod -aG (always use -aG together!), gpasswd