Few things frustrate Linux administrators like an application that works with SELinux disabled and breaks the moment it is enforcing. The correct response is not setenforce 0 — it is proper SELinux troubleshooting. Once you can read an AVC denial and fix contexts, booleans and ports the intended way, SELinux stops being an obstacle and becomes one of the strongest security layers on your RHEL 9 server.
This SELinux troubleshooting guide shows the complete workflow: find the denial in the audit log, understand what was blocked, and fix it permanently with semanage, restorecon or a local policy module generated by audit2allow.
Prerequisites – SELinux Troubleshooting on RHEL 9
- A RHEL 9, CentOS Stream 9, AlmaLinux 9 or Rocky Linux 9 server with SELinux enforcing
- Root or sudo access
- The
policycoreutils-python-utilsandsetroubleshoot-serverpackages (installed in step 1)
Step 1: Confirm the Mode and Install the SELinux Troubleshooting Tools – SELinux Troubleshooting on RHEL 9
getenforce
sestatus
dnf install -y policycoreutils-python-utils setroubleshoot-server audit
getenforce should return Enforcing. If it returns Permissive, denials are logged but not blocked — useful while diagnosing, but remember to return to enforcing afterwards with setenforce 1.
Step 2: Reproduce the Problem and Find the AVC Denial
Trigger the error again (start the service, load the web page, run the backup), then search the audit log for recent denials:
ausearch -m AVC -ts recent
grep "denied" /var/log/audit/audit.log | tail -20
A typical denial looks like this:
type=AVC msg=audit(...): avc: denied { read } for pid=1234 comm="httpd" name="index.html" dev="sda1" ino=... scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0
Read it left to right: the source context (httpd_t) tried to read a file whose target context was user_home_t. Nine times out of ten, the file simply has the wrong label — for example because it was created in a home directory and moved into the web root.

Step 3: Fix Wrong File Contexts with semanage and restorecon
For content in the wrong place, fix the label rather than the policy. Check the expected context, apply it persistently with semanage fcontext, then relabel:
ls -Z /var/www/html/index.html
semanage fcontext -a -t httpd_sys_content_t "/srv/web(/.*)?"
restorecon -Rv /srv/web
The semanage rule survives filesystem relabels, while a plain chcon does not — always prefer semanage fcontext plus restorecon in production.
Step 4: Check Booleans Before Writing Policy
Many “SELinux is blocking me” cases are a boolean away from working. Booleans are supported switches for legitimate behaviour, for example allowing Apache to connect to the network or read user content:
getsebool -a | grep httpd
setsebool -P httpd_can_network_connect 1
The -P flag makes the change persistent. Always search for a boolean before considering custom policy.
Step 5: Use audit2allow for Genuine Policy Gaps
If neither contexts nor booleans solve it, generate a small local module from the denials. Review what audit2allow proposes before installing anything:
ausearch -m AVC -ts today | audit2allow
ausearch -m AVC -ts today | audit2allow -M myappfix
semodule -i myappfix.pp
Never pipe an entire audit log blindly into a module on a production server — you might accidentally allow behaviour that should stay blocked, such as a compromised service reading shadow files. Generate rules only from denials you reproduced and understand. The sealert tool from setroubleshoot gives a human-readable summary that is excellent for this review:
sealert -a /var/log/audit/audit.log
Step 6: Allow a Service on a Non-Standard Port
Changing a daemon’s port is the other classic SELinux trap. SELinux controls which ports a service may bind, so after moving SSH to port 2222 you must register the port:
semanage port -a -t ssh_port_t -p tcp 2222
semanage port -l | grep ssh
Without this step sshd fails to start with a permission error even though the firewall is open. A similar approach applies to web servers on ports such as 8080 (http_port_t).
Step 7: Let audit2why Explain Denials in Plain Language
When an AVC line feels cryptic, pipe it through audit2why. It translates raw denials into a short explanation and usually names the boolean or context that would resolve them:
ausearch -m AVC -ts today | audit2why
Combined with sealert, this gives you two independent opinions before you change anything — exactly the kind of double-check you want before modifying security policy on a production machine.
Troubleshooting
“SELinux is preventing…” but no AVC appears: some denials are hidden by dontaudit rules. Rebuild a view with semodule -DB, reproduce the error, collect the AVC, then restore with semodule -B.
The whole system is mislabeled after a restore: schedule a full relabel with touch /.autorelabel and reboot, or run fixfiles -F onboot.
Everything works in permissive only: work through denials one service at a time using the steps above instead of switching SELinux off. On multi-service servers this is also a good reason to keep changes documented, much like you would with firewall rules in CSF.
Conclusion
Good SELinux troubleshooting is a repeatable loop: reproduce, read the AVC, fix the context, check the boolean, and only then write policy with audit2allow. Master that loop and you can keep SELinux enforcing on every RHEL 9 server — with the security benefits Red Hat designed it for. The official RHEL 9 SELinux guide is the reference to keep bookmarked.