Sub topic 2
Package management, repositories, and updates
This chapter assumes you can use sudo, edit files in /etc, and run systemctl. The examples target RHEL 9 or a compatible distribution on a test server. Run each change on a test machine first.
Package management and updates
Install only packages you need, and only from signed repositories. Confirm that GPG signature checking is on:
grep -E '^gpgcheck' /etc/dnf/dnf.conf
sudo dnf check-update --security
sudo dnf update --security -yMandatory access control with SELinux
SELinux (Security-Enhanced Linux) is a kernel policy layer that restricts processes even when they run as root. CIS expects it in enforcing mode:
getenforce
sudo sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/configBootloader, process hardening, and warning banners
CIS also asks you to disable core dumps, which can expose memory contents, and to show a legal warning before login:
# /etc/security/limits.d/50-cis.conf
* hard core 0| File | Purpose |
|---|---|
| /etc/issue | Banner shown at the local console |
| /etc/issue.net | Banner shown before remote login |
Removing and disabling unneeded services
List enabled services, then disable any you do not use:
systemctl list-unit-files --state=enabled
sudo systemctl disable --now avahi-daemon.serviceNetwork kernel parameters and unused protocols
Kernel parameters (sysctl values) control how the network stack behaves. Store them in a drop-in file, then load and verify them:
# /etc/sysctl.d/60-cis-network.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.tcp_syncookies = 1sudo sysctl --system
sysctl net.ipv4.ip_forwardConfiguring a default-deny host firewall
A default-deny firewall drops inbound traffic unless a rule allows it. The ruleset below allows loopback, replies to established connections, and SSH:
# /etc/nftables.conf
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
iif "lo" accept
ct state established,related accept
ct state invalid drop
tcp dport 22 accept
}
chain forward {
type filter hook forward priority 0; policy drop;
}
chain output {
type filter hook output priority 0; policy accept;
}
}Hardening the SSH server
Put SSH settings in a drop-in file. On RHEL, the main sshd_config includes the drop-in directory at the top, so these values take effect:
# /etc/ssh/sshd_config.d/60-cis.conf
PermitRootLogin no
PermitEmptyPasswords no
MaxAuthTries 4
X11Forwarding no
ClientAliveInterval 15
ClientAliveCountMax 3sudo sshd -t && sudo systemctl reload sshd
sudo sshd -T | grep -Ei 'permitrootlogin|maxauthtries'Exercise
Why does sshd -T matter after you edit a drop-in file?
Show answer
It prints the effective values the daemon uses, so you can confirm that an earlier file did not override your setting.