Sub topic 3
PAM, password policy, and sudo
This chapter assumes you can edit files as root, check services with systemctl, and have an OpenSCAP scan report from the previous chapter. Keep a second SSH session open whenever you change authentication, so you can recover if a change blocks login.
PAM, password policy, and sudo
PAM (Pluggable Authentication Modules) is the framework that checks passwords and starts login sessions. On RHEL, password quality rules live in /etc/security/pwquality.conf:
# /etc/security/pwquality.conf
minlen = 14
minclass = 4Put sudo rules in drop-in files under /etc/sudoers.d/, and always validate them before saving with sudo visudo -cf /etc/sudoers.d/cis-sudo.
User accounts, shells, and session environment
Service accounts should use a non-login shell. List accounts that have a login shell:
getent passwd | awk -F: '$7 !~ /nologin|false/ {print $1, $7}'Configuring journald and rsyslog
journald is the systemd logger. Set persistent storage so logs survive a reboot:
# /etc/systemd/journald.conf.d/60-cis.conf
[Journal]
Storage=persistent
Compress=yesApply it with sudo systemctl restart systemd-journald. rsyslog writes text log files, so confirm it runs with systemctl is-active rsyslog.
Auditing security-relevant events with auditd
auditd is the Linux audit daemon. It records file access and changes. Add watch rules in /etc/audit/rules.d/50-cis.rules:
-w /etc/sudoers -p wa -k scope
-w /etc/passwd -p wa -k identity
-w /etc/shadow -p wa -k identityLoad the rules and search for events by key: sudo augenrules --load then sudo ausearch -k identity.
File integrity monitoring with AIDE
AIDE (Advanced Intrusion Detection Environment) stores hashes and permissions of files, then reports changes. Build the database and then check against it:
sudo aide --init
sudo mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
sudo aide --checkThe database paths vary by distribution, so confirm them in aide.conf.
File permissions and system maintenance checks
Find world-writable files on local filesystems:
sudo find / -xdev -type f -perm -0002Automating remediation and detecting drift
Drift is a gradual change away from the hardened state. Scan on a schedule and save each result with its date, so you can compare reports over time:
sudo mkdir -p /var/log/oscap
sudo oscap xccdf eval \
--profile xccdf_org.ssgproject.content_profile_cis_server_l1 \
--results /var/log/oscap/results-$(date +%F).xml \
/usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml> Avoid running --remediate on a production server without a snapshot and a second session open.
Handling exceptions and documenting risk acceptance
Some recommendations conflict with a workload. Record each exception with its reason and an owner:
| Recommendation | Reason | Approved by | Review date |
|---|---|---|---|
| Disable cramfs module | Required by backup software | Security lead | 2027-03-31 |
Exercise
Why should you run sudo visudo -cf or sshd -t before reloading a changed configuration?
Show answer
A syntax error can stop sudo or SSH from working, and you may lose the ability to get root access. Validation catches the error before the service reloads.