Mikey’s Linux Field NotesAll topics

GUIDE 14 / SECURITY

SELinux

Inspect mandatory access controls, investigate denials, and restore file labels.

2 quick lessons · Examples to adapt to your server
In this guide
Inspect SELinux mode and labelsRestore the expected file label

Commands use class paths and example filenames. Replace placeholders and inspect the target before making changes.

01

Inspect SELinux mode and labels

SELinux adds policy checks beyond ordinary file permissions. Nginx processes run in httpd_t. A readable Unix mode can still result in a denied request if the label is unsuitable.

COMMANDS & EXAMPLES
getenforce
sestatus
ps -eZ | grep nginx
ls -lZ /usr/share/itfdn-docs
sudo ausearch -m avc -ts recent
Field note

An AVC identifies source context, target context, object class, and denied operation. permissive=0 means the denial was enforced. Do not disable SELinux to work around a labeling problem.

02

Restore the expected file label

Moving a file within a filesystem can preserve its old label. In the class exercise, a home-created notes.html retained user_home_t and nginx received 403 until its path label was restored.

COMMANDS & EXAMPLES
matchpathcon /usr/share/itfdn-docs/notes.html
restorecon -v /usr/share/itfdn-docs/notes.html
ls -lZ /usr/share/itfdn-docs/notes.html
Field note

restorecon uses the configured path mapping. In the observed exercise that mapping was usr_t and serving succeeded. Dedicated web roots commonly use httpd_sys_content_t; persistent custom mappings should be defined with semanage fcontext before restorecon.