Linux

SELinux Troubleshooting on RHEL and Rocky Linux: Fix AVC Denials Without Disabling It

Aseem Kishore
19 min read

The Back Room Tech is reader-supported. We may earn a commission when you buy through links on our site. Learn more.

Your service works when you run it by hand but fails with “Permission denied” as a daemon. Or NGINX returns 403 or 502 for no clear reason. On RHEL, Rocky Linux, or AlmaLinux, SELinux is a likely cause. The good news is that SELinux logs nearly everything it blocks (the exception is dontaudit rules, covered in Issue 6), so you can usually find the exact denial and fix that one thing.

So how do you fix it without setenforce 0? Find the AVC (Access Vector Cache) denial with ausearch, then read it with sealert or audit2why. Apply the narrowest fix that works, in this order: an existing boolean, a persistent file label (semanage fcontext + restorecon), a port label (semanage port), and a reviewed custom policy module only as a last resort. That order follows Red Hat’s own Troubleshooting problems related to SELinux chapter for RHEL 10.

Red Hat’s documentation evolves between releases, so always confirm specifics against the current docs.redhat.com page for your RHEL version.

Prerequisites

  • OS: RHEL 9 or RHEL 10. Rocky Linux 9/10 and AlmaLinux 9/10 rebuild RHEL’s SELinux packages, so the commands here work the same way, though exact tool versions can vary slightly by release.
  • Access: root or sudo.
  • Policy: SELinux enabled with the default targeted policy.
  • Packages: On RHEL 9 and RHEL 10, setroubleshoot-server typically provides sealert, and policycoreutils-python-utils typically provides semanage, audit2allow, and audit2why; exact package contents can vary by minor release.

This guide follows Red Hat’s RHEL 10 Using SELinux docs, and the workflow and tools are the same on RHEL 9. Exact output, such as the default port lists, can differ slightly between policy versions. It works the same on a production cluster or a Rocky Linux mini PC in your homelab.

Quick Diagnosis

1. Confirm SELinux is enforcing

getenforce
sestatus

Expected output (trimmed):

Enforcing
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing

If getenforce says Permissive or Disabled, SELinux isn’t blocking anything. Look elsewhere.

Output of getenforce and sestatus showing SELinux status enabled, Loaded policy name targeted, Current mode enforcing, Mode from config file enforcing

2. Install the diagnostic tools

sudo dnf install setroubleshoot-server policycoreutils-python-utils

3. Make sure auditd is running

AVC denials go to /var/log/audit/audit.log through the audit daemon (auditd). If auditd is stopped, ausearch returns nothing, even while SELinux is blocking your service.

sudo systemctl status auditd

You want to see Active: active (running). If it’s stopped, start it with sudo systemctl start auditd.

On some RHEL-family systems, systemctl restart auditd doesn’t behave like a normal service restart. If that command doesn’t work for you, use sudo service auditd restart instead.

4. Reproduce the failure, then search

# -m selects record types; -ts recent = the last 10 minutes
sudo ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent

The RHEL 10 docs use this multi-type query. On RHEL 9, ausearch -m AVC -ts recent alone catches the kernel denials you’ll usually care about. If you see <no matches>, run the failing action again and search right away. A missed time window is the most common reason for an empty result.

A typical denial looks like this (illustrative):

type=AVC msg=audit(1761458400.123:512): avc:  denied  { read } for  pid=2481 comm="nginx" name="index.html" dev="dm-0" ino=33583 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_t:s0 tclass=file permissive=0
Raw ausearch AVC denial record for nginx showing denied { read }, scontext httpd_t, tcontext var_t and tclass=file

5. Read the key fields

FieldMeaningIn the example
denied { ... }The operation that was blockedread
commThe command that tried itnginx
scontextSource: the process’s SELinux domainhttpd_t
tcontextTarget: the label on the file or portvar_t
tclassKind of objectfile
permissive0 = blocked, 1 = only logged0

The type pair tells you most of the story. Here, httpd_t is trying to read something labeled var_t. That usually points to a labeling problem, though it can also mean the process is running in the wrong domain or genuinely needs a policy rule, so confirm before you pick a fix.

6. Get a plain-language explanation

sudo sealert -a /var/log/audit/audit.log

sealert groups denials and prints lines like “SELinux is preventing /usr/sbin/nginx from read access on the file index.html”. Then it lists ranked suggestions, each with a confidence score and the exact command to run. With setroubleshoot-server installed, the journal also logs a short version. It points to sealert -l <ID> for a single alert.

sealert output reporting that SELinux is preventing /usr/sbin/nginx from read access on index.html, with semanage fcontext and restorecon suggestions for /srv/mysite

For a quick answer on whether a boolean would fix it, use audit2why:

# --raw outputs unformatted records that audit2why can parse
sudo ausearch -m AVC -ts recent --raw | audit2why

audit2why reports either a missing type enforcement rule or a boolean that would allow the access. When it names a boolean, it also gives the setsebool command. Treat both tools as advisors. Read every suggestion before you run it.

Warning: Don’t “test” with setenforce 0. It switches the whole system to permissive mode, so every confined service loses protection. It’s also easy to forget to switch back. If you need to confirm SELinux is the cause, make only the affected domain permissive (see Issue 6).

The Fix Order

Work through these in order. Stop at the first one that resolves the denial.

OrderFixUse whenCommand
1Booleanaudit2why/sealert names onesetsebool -P name on
2File contexttcontext is the wrong type for the pathsemanage fcontext -a + restorecon -Rv
3Port labeltclass=tcp_socket with name_bind or name_connectsemanage port -a
4Local moduleNothing above fits and the access is legitimateaudit2allow -M, review, semodule -i

Common Issues and Solutions

Issue 1: Web server returns 403 for content in a custom directory

Symptoms:

  • NGINX or Apache returns 403 Forbidden for files in /srv/mysite. Moving the same files into /var/www/html works.
  • Unix permissions (ls -l) look correct.
  • The AVC shows comm="nginx" or comm="httpd", tcontext=...:var_t (or default_t), and tclass=file or dir.

Why it happens: The web server runs in the httpd_t domain. That domain can read content labeled httpd_sys_content_t. New directories outside /var/www get a generic label based on their location, and that label isn’t on httpd_t‘s allow list.

Fix: Check the current label first:

ls -Zd /srv/mysite
unconfined_u:object_r:var_t:s0 /srv/mysite

Add a persistent rule, then apply it:

# (/.*)? makes the rule match the directory and everything beneath it
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/mysite(/.*)?"
# -R recurses; -v prints each change
sudo restorecon -Rv /srv/mysite
Relabeled /srv/mysite from unconfined_u:object_r:var_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
Relabeled /srv/mysite/index.html from unconfined_u:object_r:var_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0

If the app needs to write there, such as for uploads or cache, label only that subdirectory httpd_sys_rw_content_t. Don’t relabel the whole tree.

ls -Zd /srv/mysite showing var_t before, then semanage fcontext and restorecon -Rv output, then ls -Zd showing httpd_sys_content_t after

Verification:

getenforce
curl -I http://localhost/

You should see Enforcing and HTTP/1.1 200 OK.

Issue 2: chcon fix disappears after a reboot, update, or restorecon

Symptoms:

  • You ran chcon -t httpd_sys_content_t ... and it worked.
  • Weeks later the 403s come back with no config change.

Why it happens: chcon changes only the label stored on disk right now. It adds nothing to SELinux’s file-context database. The next restorecon, package-triggered relabel, or full relabel resets the file to whatever the database says. semanage fcontext writes the rule into that database, so every later relabel applies your label.

Fix: Replace the chcon change with the persistent pair from Issue 1:

sudo semanage fcontext -a -t httpd_sys_content_t "/srv/mysite(/.*)?"
sudo restorecon -Rv /srv/mysite

Verification: Confirm the rule is stored, then rerun restorecon. It should report no changes.

sudo semanage fcontext -l -C
sudo restorecon -Rnv /srv/mysite    # -n = dry run; no output means labels already match

-C lists only local customizations, so your rule should appear there.

Issue 3: Reverse proxy returns 502 Bad Gateway to a backend app

Symptoms:

  • NGINX proxy_pass or Apache mod_proxy to 127.0.0.1:3000 (Node.js, Python, etc.) returns 502.
  • The NGINX error log shows connect() to 127.0.0.1:3000 failed (13: Permission denied).
  • The AVC shows denied { name_connect } and tclass=tcp_socket.

Why it happens: By default, httpd_t is denied name_connect to ports outside its allowed list, which is why a reverse proxy’s outbound call to a local backend gets blocked. The targeted policy ships more than one boolean for this, and they aren’t interchangeable.

httpd_can_network_connect permits broad outbound connectivity to any port httpd_t is otherwise allowed to reach. httpd_can_network_relay is narrower and intended specifically for forward/reverse proxy behavior, but whether it applies depends on the SELinux type labeling your backend’s port.

Fix: Before enabling anything, check the backend port’s labeled type and the available httpd booleans:

sudo semanage port -l | grep -w 3000
sudo semanage boolean -l | grep httpd

If the backend port’s type is one httpd_can_network_relay covers, enable the narrower boolean:

# -P makes the change persistent across reboots
sudo setsebool -P httpd_can_network_relay on

If the port isn’t labeled with a type the relay boolean covers, label it with semanage port -a as described in Issue 4, then recheck whether the relay boolean now applies. Reserve the broader boolean for cases that genuinely need it:

getsebool httpd_can_network_connect
httpd_can_network_connect --> off
sudo setsebool -P httpd_can_network_connect on

Use httpd_can_network_connect only when the app needs to reach arbitrary remote hosts or ports, not a single fixed backend. Read each boolean’s description with semanage boolean -l | grep httpd before you decide, since the right default label and port type can vary by policy version.

Verification: curl -I http://localhost/ returns the backend’s response instead of 502, and getenforce still shows Enforcing.

Issue 4: Service can’t listen on a non-default port

Symptoms:

  • NGINX or Apache fails to start after you change listen to a custom port such as 8090.
  • The journal shows bind() to 0.0.0.0:8090 failed (13: Permission denied).
  • The AVC shows denied { name_bind } and tclass=tcp_socket.

Why it happens: Ports carry SELinux types too. httpd_t can bind to ports labeled http_port_t, and your new port isn’t one of them.

Fix: See what’s labeled now, and whether your port already has a type:

sudo semanage port -l | grep -w http_port_t
sudo semanage port -l | grep -w 8090
http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000

The exact list varies by policy version. No output from the second command means the port is unlabeled, so add it:

# -a adds a record; -t sets the type; -p sets the protocol
sudo semanage port -a -t http_port_t -p tcp 8090

If the port already belongs to another type, you’ll get ValueError: Port tcp/8090 already defined. Use -m (modify) instead of -a. Port 8080, for example, is commonly preassigned to http_cache_port_t.

sudo semanage port -l | grep -w http_port_t
http_port_t                    tcp      8090, 80, 81, 443, 488, 8008, 8009, 8443, 9000
semanage port -l filtered to http_port_t before and after adding tcp port 8090, with 8090 at the start of the comma-separated list after the change

Verification:

sudo systemctl restart nginx
systemctl status nginx --no-pager

Look for active (running).

Issue 5: Custom systemd service fails with status=203/EXEC

Symptoms:

  • systemctl status myapp shows code=exited, status=203/EXEC.
  • The binary runs fine from your shell.
  • The AVC shows denied { execute } and tcontext=...:user_home_t (the binary lives under /home).

status=203/EXEC on its own is a generic systemd execution failure; it can also show up for a missing binary, bad permissions, or a bad interpreter path, not just an SELinux denial. Treat it as a hint to go look, not as proof. The AVC record with denied { execute } is the actual evidence.

Why it happens: The SELinux domain a service runs in depends on the unit file, any SELinuxContext= override, and whether a domain transition applies, so it isn’t always the same domain by default. Check the AVC’s scontext field, and the unit’s configured execution context, before assuming which domain is involved.

Whatever domain shows up in scontext, the underlying problem is usually the same: that domain’s policy doesn’t allow executing files labeled as user home content. The binary runs fine from your shell because your interactive login session is confined differently than the service’s domain.

Fix: The cleanest fix is to install the binary somewhere standard, like /usr/local/bin. Prefer cp over mv: a copied file generally picks up the label appropriate to its new location, while a moved file, if it stays on the same filesystem, tends to keep its original label.

If you do move a file instead, run restorecon on it afterward to be safe. If the binary has to stay in an app directory, label it persistently:

sudo semanage fcontext -a -t bin_t "/opt/myapp/bin(/.*)?"
sudo restorecon -Rv /opt/myapp/bin

Then run ausearch again and check the scontext on any new record. If the process now hits a different denial, such as writing logs, fix that one the same way. Don’t jump straight to audit2allow.

Verification:

sudo systemctl restart myapp
systemctl status myapp --no-pager
getenforce
systemctl status output for myapp showing active (running), followed by getenforce returning Enforcing

Issue 6: You need to confirm SELinux is the cause without disabling it

Symptoms:

  • You see intermittent failures and aren’t sure SELinux is involved.
  • ausearch shows nothing, but the service is confined.

Why it happens: Some denials are marked dontaudit and never get logged. In other cases, the failing path just isn’t obvious yet.

Fix: Make only the suspect domain permissive using semanage permissive, which, per Red Hat’s SELinux mode documentation, applies to that domain only rather than switching the whole system to permissive mode. It keeps running, but its denials get logged instead of enforced:

sudo semanage permissive -a httpd_t
sudo semanage permissive -l          # confirm it's listed

Reproduce the problem and collect the AVCs (they’ll show permissive=1). Then remove the exception right away:

sudo semanage permissive -d httpd_t

If you suspect hidden dontaudit denials, sudo semodule -DB turns them off for now. Expect a lot of log noise. Restore normal behavior with sudo semodule -B when you’re done.

Verification: sudo semanage permissive -l no longer lists your domain, and getenforce returns Enforcing.

Issue 7: Container gets “Permission denied” on a bind-mounted volume

Symptoms:

  • Podman or Docker can’t read or write -v /srv/appdata:/data even though ls -l permissions look fine.
  • The AVC shows scontext=...:container_t and a host label like var_t or user_home_t.

Why it happens: Containers typically run as container_t, and container_file_t is the standard label for volumes they’re allowed to use. Exact access can still vary with the container domain, policy, categories, and special or read-only mounts. In the common case the Unix permissions are fine but the SELinux label doesn’t match, so access is denied anyway.

Fix: Let the container engine relabel the path:

# :Z = private label, only this container can use the path
podman run -d -v /srv/appdata:/data:Z docker.io/library/nginx

# :z = shared label, multiple containers can use the path
podman run -d -v /srv/shared:/data:z docker.io/library/nginx

Docker on RHEL-family hosts accepts the same suffixes when its SELinux support is enabled. Check the podman-run(1) man page on your version for the exact wording.

Warning: Never use :Z or :z on system or home directories such as /home, /etc, or /usr. The engine relabels the entire host path, which can break your login or other services. Mount a dedicated subdirectory instead.

Verification:

ls -Zd /srv/appdata
system_u:object_r:container_file_t:s0:c123,c456 /srv/appdata

The category pair (c123,c456) will be different on your system. With :z you’ll typically see plain s0, though exact output can vary with the container engine and existing labels.

Issue 8: audit2allow “fixed” it, but new denials keep appearing

Symptoms:

  • You installed an audit2allow -M module, and a related denial keeps popping up in a different form.

Why it happens: audit2allow generates rules from the audit records you feed it, and the result can be broader than the single denial you were looking at. If the real problem was a wrong file or port label, the module hides that mistake. The label stays wrong for everything else.

Fix: Remove the module and go back to the fix order. Use audit2allow only when nothing narrower applies:

sudo semodule -r my-httpd                       # remove the earlier module
sudo ausearch -m AVC -ts recent --raw | audit2allow -M my-httpd
cat my-httpd.te                                 # READ THIS before installing
sudo semodule -i my-httpd.pp

Warning: Never install an audit2allow -M module without reading the .te file. Reject it if it grants access to broad types like default_t, var_t, or user_home_t, or permissions you didn’t expect. That pattern means a labeling fix was the right answer.

audit2allow is the right tool for legitimate access that no boolean or label covers. A typical case is a third-party app doing something the policy authors never planned for.

Error Messages Quick Reference

Error / Log messageLikely causeQuick fix
ausearch: <no matches>auditd stopped or time window missedsystemctl status auditd, reproduce, search again
sealert: command not foundsetroubleshoot-server missingdnf install setroubleshoot-server
semanage: command not foundpolicycoreutils-python-utils missingdnf install policycoreutils-python-utils
denied { read } … tcontext=…var_tWrong file labelsemanage fcontext -a + restorecon -Rv
(13: Permission denied) on connect()httpd outbound blockedCheck port type, then setsebool -P httpd_can_network_relay on or httpd_can_network_connect on
denied { name_bind }Port not labeled for the servicesemanage port -a -t TYPE -p tcp PORT
ValueError: Port tcp/N already definedPort already has another typeUse semanage port -m
status=203/EXEC + denied { execute }Binary labeled user_home_tMove it or label it bin_t
Container Permission denied on volumeHost path not container_file_tAdd :Z or :z to the mount

Platform-Specific Notes

RHEL 9 vs RHEL 10

The workflow and tools are largely the same on both releases: ausearch, sealert, audit2why, semanage, restorecon, and audit2allow. Policy contents do change between versions. A boolean, a default port list, or a default label can differ. Always check on the actual host with semanage boolean -l and semanage port -l instead of copying values from another server.

Rocky Linux and AlmaLinux

Both rebuild RHEL’s SELinux packages, so the commands here apply the same way, though exact tool versions can vary slightly by release. Rocky’s QA team checks for SELinux denials after install as part of its server test case. A clean install shouldn’t show any AVCs before you add your own workloads.

Configuration Issues

SELinux mode is set in /etc/selinux/config. The correct baseline is:

# /etc/selinux/config
SELINUX=enforcing
SELINUXTYPE=targeted

Common mistakes:

  • Setting SELINUX=disabled “temporarily.” Files created while SELinux is off get no labels. Turning it back on then needs a full relabel. Keep it enforcing.
  • Leaving SELINUX=permissive after debugging. This is just as bad. Use per-domain permissive instead (Issue 6).
  • Using chcon in deployment scripts. Use semanage fcontext so labels survive (Issue 2).

Warning: Full filesystem relabel. sudo touch /.autorelabel followed by a reboot (or fixfiles -F onboot) relabels every file at boot. Expect a long boot on large filesystems or a NAS-sized array. Customizations made only with chcon get wiped. Use it only after SELinux was disabled or the labels are badly damaged, never as a routine fix. Schedule a maintenance window, and make sure the box is on a UPS so a power cut doesn’t interrupt it.

Getting Help

When you ask for help, collect this first:

  • sestatus output
  • sudo ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent output
  • sudo sealert -a /var/log/audit/audit.log output
  • ls -Zd for the paths involved, and semanage fcontext -l -C / semanage port -l -C for your local customizations
  • If auditd isn’t running, AVCs land in the kernel log: sudo journalctl -k --grep=avc

Useful references:

Prevention Tips

  • Put labels in your automation. Add semanage fcontext and restorecon steps to your Ansible roles or install scripts, next to the step that creates the directory.
  • Use standard paths when you can. Content in /var/www, binaries in /usr/local/bin, and data in /var/lib/appname all get sensible labels automatically.
  • Copy, don’t move, into labeled trees. mv often keeps the old label, especially within the same filesystem. Run restorecon -Rv after any move to be sure.
  • Check ports before you pick them. Run semanage port -l | grep -w PORT before changing a listen port.
  • Review local customizations periodically. semanage export dumps everything you’ve changed. You can version it and rebuild a server with the same changes.
Help & Answers

Frequently Asked Questions

4 questions

How do I know if SELinux is actually causing my problem?

Reproduce the failure and run ausearch -m AVC -ts recent. A matching denied record with your process’s comm is strong evidence that it is.

If nothing shows up, check that auditd is running, then try per-domain permissive. If the problem goes away in permissive mode, SELinux is very likely involved, though a denial can be incidental rather than the only cause, so check the logged AVCs before you change anything.

Is it safe to use setenforce 0 to test?

It works, but it removes protection from every confined service on the host. semanage permissive -a DOMAIN gives you the same diagnostic for just one service. Always finish in enforcing mode.

When is audit2allow actually the right tool?

Use it when the access is legitimate and no boolean, file label, or port label covers it. Even then, read the generated .te file before you install it.

Why does my container get Permission denied when file permissions look fine?

SELinux checks labels on top of Unix permissions. The host path needs container_file_t, which the :Z or :z mount suffix applies.

Wrapping Up

You can now trace a failure to a specific AVC denial, read it, and fix that one access. Most of the time the fix is a boolean or a label. The ordered path (boolean → file context → port → reviewed module) handles nearly every real-world case.

In my view, most “SELinux broke my server” stories are really labeling problems. Once semanage fcontext is a habit, SELinux rarely gets in your way.

StepActionApplies To
1getenforce, sestatus, check auditdAll
2ausearch + sealert / audit2whyAll
3setsebool -PProxies, network access
4semanage fcontext + restoreconCustom dirs, binaries
5semanage portNon-default ports
6:Z / :zPodman/Docker volumes
7Reviewed audit2allow moduleLast resort

Last updated: 2026-10-26 | Applies to SELinux on RHEL 9/10, Rocky Linux 9/10, and AlmaLinux 9/10