Sub topic 1
What the CIS Benchmarks are and how they are organized
Prerequisites
This chapter assumes you can use the Linux command line and a text editor, read systemd unit status, and use sudo. You need root or sudo access to a test server or virtual machine. Do not try these steps on a production host first.
What the CIS Benchmarks are
The Center for Internet Security (CIS) publishes Benchmarks. A Benchmark is a written configuration guide for an operating system or software product. Each Benchmark is a numbered list of recommendations. A recommendation names a setting, explains the risk it reduces, and gives an audit procedure and a fix.
Recommendations are grouped into sections such as filesystem, services, network, logging, and access control. A scored recommendation can be checked automatically. A manual recommendation needs a person to inspect the system.
Choosing a benchmark and profile
A profile is a named subset of recommendations. Level 1 profiles hold low-impact settings that rarely break services. Level 2 profiles add stricter settings for high-security environments, and they can break workloads. Server and Workstation profiles separate recommendations by system role.
For a server, start with the Server Level 1 profile. Move to Level 2 only after you test each added setting against your workload.
A safe hardening workflow
Follow this order for every change:
- Scan the untouched host and save the report as a baseline.
- Take a snapshot of the virtual machine, or back up
/etc. - Apply one group of changes.
- Scan again and compare the result with the baseline.
- If a service breaks, restore the snapshot.
Scanning with OpenSCAP and reading the results
OpenSCAP is an open-source tool that checks a system against SCAP content. On RHEL 9, the SCAP content file includes the CIS profiles.
# List the profiles in the content file
oscap info /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml
# Run the CIS Server Level 1 profile
sudo oscap xccdf eval \
--profile xccdf_org.ssgproject.content_profile_cis_server_l1 \
--results results.xml \
--report report.html \
/usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xmlOpen report.html in a browser. Each failing rule shows its rule ID and a remediation hint. Use results.xml when a script needs to compare scans.
Filesystem hardening: kernel modules, partitions, and mount options
A kernel module is a loadable driver. CIS asks you to block modules for filesystems that a server does not use, because each one adds attack surface. Create this file:
# /etc/modprobe.d/cramfs.conf
install cramfs /bin/false
blacklist cramfsThen verify the block:
lsmod | grep cramfs
modprobe -n -v cramfsThe first command prints nothing when the module is not loaded. The second prints install /bin/false when the block works.
Mount options control how a filesystem behaves. nodev blocks device files, nosuid ignores the setuid bit, and noexec blocks running programs. CIS asks for these options on /tmp. Mount options live in /etc/fstab. A bad entry can stop the boot, so apply the change with a remount and check it:
# /etc/fstab entry for /tmp
tmpfs /tmp tmpfs defaults,rw,nosuid,nodev,noexec,relatime,size=2G 0 0sudo mount -o remount /tmp
findmnt --target /tmpExercise
A web server needs to run scripts from /tmp. Which CIS mount option conflicts with this, and what should you check before you apply it?
Show answer
The noexec option blocks running programs from /tmp, so the scripts will fail. Check the workload first, or move the scripts to a directory without noexec.