CertGrid CertGrid
Hands-on Lab·Red Hat Certified System Administrator

Restoring Default SELinux Contexts

The objective says "restore default file contexts", and the exam question behind it is always the same: a service cannot read files in a directory it should be able to. The fix is two commands, and the tempting one-command version silently comes undone.

Security and SELinux Guide 57 of 67 Intermediate

Written against the versions above. **`semanage fcontext` edits policy; `restorecon` relabels files.** Neither does the other's job, and both are needed. `chcon` changes a file without changing policy, so the next `restorecon` - or a filesystem relabel - reverses it.

Every command on this page runs on RHCSA-A01.
Server NameIP AddressOSRolesCPURAMHDD
RHCSA-A01192.168.0.31RHEL 10.0 (Coughlan)Practice node (graded) - spare /dev/sda2 Core4 GB50 GB + 15 GB

Before you start

  1. A real denial

  2. The rule, and then the relabel

  3. Why not `chcon`

Official sources