This episode covers SELinux and Mandatory Access Control on Rocky Linux: the difference between DAC and MAC, the Enforcing, Permissive, and Disabled modes, file contexts and semanage fcontext, booleans, and troubleshooting with ausearch and sealert.

In the previous episode 13, you built the outer defense wall with the firewall. But one question remains unanswered: who protects the system from within — when a process has already gotten in, or when root itself makes a mistake? The answer is SELinux, and this episode will change how you think about Linux security.
SELinux is often seen as a bogeyman: many tutorials suggest setenforce 0 as the first solution to every problem. In this episode you'll learn to use SELinux as a security layer that actually gives you valuable information — and solve problems by working with SELinux, not against it.
Traditional Linux uses DAC (Discretionary Access Control) — the control you learned in episode 6. The file owner decides who can access it, and root has unlimited power. The problem: if a process is successfully exploited, it inherits all the rights of its owner — including root rights.
MAC (Mandatory Access Control) layers on top of DAC. SELinux enforces system-defined policies, regardless of the file owner's wishes or root's power. Even root is restricted by SELinux policy rules:
sestatusgetenforceThe key difference: DAC is "the owner may decide", MAC is "system policy forces everyone — including root".
| Mode | Behavior |
|---|---|
Enforcing | Policy is enforced; violations are blocked and logged |
Permissive | Violations are only logged, not blocked |
Disabled | SELinux is completely inactive |
getenforcesetenforce 1
setenforce 0setenforce 0 moves to Permissive — useful for diagnostics, but don't make it a permanent habit.
Warning
setenforce 0 only takes effect at runtime and reverts to the configuration in /etc/selinux/config after a reboot. Changing the default mode in that file — from enforcing to disabled — requires a reboot and opens the system up from a security layer that is active by default.
The default mode is stored in /etc/selinux/config:
cat /etc/selinux/configThe SELINUX=enforcing line sets the mode at every boot. For production, the right target is enforcing — not disabled.
Every file on an SELinux system has a context label — type information that determines how processes can interact with it. View it with ls -Z:
ls -Z /var/www/html/index.htmlps -efZ | grep httpdA context looks like system_u:object_r:httpd_sys_content_t:s0 — the last part (the type) is what's most often relevant. A web server needs the httpd_sys_content_t type to be able to read files.
If a file has the wrong type, SELinux blocks access even when the DAC permissions are correct. Fix it with restorecon:
restorecon -Rv /var/www/htmlchcon -t httpd_sys_content_t /var/www/html/index.htmlrestorecon restores labels according to the default policy. chcon changes them manually — but chcon changes don't survive a context restoration.
To make context changes permanent — especially for non-standard directories — use semanage:
semanage fcontext -a -t httpd_sys_content_t "/data/web(/.*)?"restorecon -Rv /data/websemanage fcontext -l | grep /dataWith semanage fcontext, rules are stored in the policy — every subsequent restorecon will always apply the correct label.
Booleans are switches that change SELinux policy behavior without writing new rules — the official shortcut for allowing frequently needed access.
getsebool -agetsebool -a | grep httpdA real-world example: allowing httpd to make outbound connections (a proxy or integration pattern):
setsebool -P httpd_can_network_connect ongetsebool httpd_can_network_connect-P makes the change permanent (stored in the policy). Without -P, the change only applies at runtime and is lost on reboot.
When SELinux blocks something, it records it in the audit log. Two tools help you read it:
ausearch -m avc -ts recentausearch -m avc --start todayausearch -m avc displays AVC (Access Vector Cache) events — SELinux access denials. The output includes the process, source and target types, and the reason for the denial.
For fix recommendations, sealert translates technical messages into suggestions:
sealert -a /var/log/audit/audit.logWhen a service fails to read a file:
ausearch -m avc -ts recent to confirm an SELinux denial.semanage fcontext + restorecon.setsebool -P.setenforce 0 shortcut; use Permissive only temporarily to confirm the cause.setenforce 0
# coba ulang operasi yang gagal, lalu kembali
setenforce 1In this episode 14, you understood SELinux on Rocky Linux: the difference between DAC and MAC, the three modes Enforcing, Permissive, and Disabled, context labels with ls -Z and fixing them via chcon, restorecon, and semanage fcontext, booleans with getsebool and setsebool -P, and troubleshooting with ausearch and sealert.
Key takeaways:
enforcing; setenforce 0 is only for momentary diagnostics.semanage fcontext for permanent labels on non-standard directories.ausearch -m avc and sealert are the first source when investigating SELinux denials.In the next episode 15, we will discuss SSH hardening and remote access — modern sshd configuration, ed25519 key-based authentication, tunneling with -L, -R, and -J, and hardening like fail2ban and user restrictions. Security from within is strong; now it's time to secure the front door!