---
title: "SELinux on AlmaLinux and Rocky Linux: read and fix denials · CloudSat"
description: "Keep SELinux enforcing on RHEL, AlmaLinux and Rocky Linux: check the mode, read AVC denials, fix labels, ports and booleans, and disable it the supported way."
url: https://cloudsat.io/learn/selinux-on-rhel-almalinux-and-rocky-linux
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[Security](https://cloudsat.io/learn/topic/server-security)

# SELinux on AlmaLinux and Rocky Linux: read and fix denials

Keep SELinux enforcing on RHEL, AlmaLinux and Rocky Linux: check the mode, read AVC denials, fix labels, ports and booleans, and disable it the supported way.

CloudSat team November 18, 2026 7 min read

Most "SELinux broke my app" moments come down to one of three things: a file with the wrong label, a port the policy does not know, or a boolean that is switched off. Each one is fixed with a single command, and none of them requires turning SELinux off. This guide covers RHEL 9 and 10 and their rebuilds, AlmaLinux and Rocky Linux, plus CentOS Stream and Fedora, which work the same way.

## What SELinux decides

Classic Linux permissions ask whether a user may touch a file. SELinux adds a second question that root cannot skip: may this *kind of process* touch this *kind of object*? Every process runs in a domain, such as `httpd_t` for Apache or nginx, and every file, port and socket carries a type, such as `httpd_sys_content_t` for web content. The policy lists which domains may do what to which types. Anything not listed is refused and logged as an AVC (access vector cache) denial.

The practical consequence: a compromised web server process that tries to read `/etc/shadow` or an SSH key in a home directory is stopped by the policy, even when file permissions would have allowed it. That containment is the reason to keep it on.

## Check the current state

```bash
getenforce
sestatus
grep ^SELINUX= /etc/selinux/config
```

| Mode | Policy checked | Access blocked | Denials logged |
| --- | --- | --- | --- |
| Enforcing | yes | yes | yes |
| Permissive | yes | no | yes |
| Disabled | no | no | no |

`getenforce` shows the running mode. The config file shows the mode the next boot will use. If the two disagree, someone changed the mode at runtime.

## Switch modes the gentle way

`sudo setenforce 0` switches to permissive until the next reboot, and `sudo setenforce 1` returns to enforcing. That is a quick test: if an app works in permissive and fails in enforcing, SELinux is involved. Switch back right away, because permissive protects nothing.

A narrower tool is better for a long investigation. Make a single domain permissive while the rest of the system stays enforcing:

```bash
sudo semanage permissive -a httpd_t    # only the web server domain stops being blocked
sudo semanage permissive -l            # list permissive domains
sudo semanage permissive -d httpd_t    # back to enforcing for that domain
```

`semanage` and `audit2allow` come from the `policycoreutils-python-utils` package, and `sealert` from `setroubleshoot-server`. Install both with `sudo dnf install policycoreutils-python-utils setroubleshoot-server`.

## Read a denial before you change anything

Denials land in the audit log. Ask for the recent ones and let `audit2why` explain them:

```bash
sudo ausearch -m AVC,USER_AVC -ts recent
sudo ausearch -m AVC -ts recent | audit2why
sudo sealert -a /var/log/audit/audit.log    # plain-language advice per denial
```

A typical denial looks like this:

```text
type=AVC msg=audit(1795003211.482:913): avc:  denied  { read } for  pid=2214 comm="nginx" name="index.html" dev="vda1" ino=393224 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 process `nginx`, running in domain `httpd_t` (the `scontext`), tried to `read` a `file` labeled `user_home_t` (the `tcontext`). Web server domains may not read home directory content, so the label is the problem, not the policy.

If an app fails and the log stays empty, the denial may be hidden by a `dontaudit` rule. `sudo semodule -DB` rebuilds the policy with those rules off, so everything gets logged. Run `sudo semodule -B` when you are done to restore them.

## Fix 1: the file has the wrong label

This is the most common case, and it usually starts with `mv`. Moving a file keeps the label it had in its old location, while copying it creates a new file that gets the label of its destination. Site files built in a home directory and moved to `/srv/www` keep `user_home_t`, and nginx is refused.

Tell the policy what the directory should be, then apply it:

```bash
ls -Z /srv/www
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/www(/.*)?"
sudo restorecon -Rv /srv/www
```

`restorecon -Rnv` shows what would change without changing it. Avoid `chcon` for anything permanent: it labels files directly, and the next relabel or `restorecon` run puts the policy's label back. Apps that write uploads or caches need `httpd_sys_rw_content_t` on those directories only.

## Fix 2: the port is not labeled

A service can bind only ports labeled for its domain. Moving a web app to port 8090, or SSH to a new port, fails until the port gets the right type:

```bash
sudo semanage port -l | grep -w http_port_t     # ports web server domains may use
sudo semanage port -a -t http_port_t -p tcp 8090
```

If the port already belongs to another type, `-a` refuses it as already defined. Use `-m` instead of `-a` to move it to the new type.

## Fix 3: a boolean is off

Booleans are switches the policy authors built in for common needs. Reverse proxies are the classic example: nginx forwarding to an app on `127.0.0.1:3000` is denied until it may open network connections.

```bash
getsebool -a | grep ^httpd_
sudo setsebool -P httpd_can_network_connect on
```

`-P` writes the change to the policy so it survives a reboot. Without it, the setting lasts until the next boot.

| Boolean | Turn it on when |
| --- | --- |
| `httpd_can_network_connect` | the web server proxies to an app or an API |
| `httpd_can_network_connect_db` | PHP or another web app talks to a remote database |
| `httpd_can_sendmail` | a web app sends mail through the local MTA |
| `httpd_use_nfs` | site files live on an NFS share |

## Containers need labels too

Podman labels containers by default on these systems, and Docker does when its daemon runs with SELinux support turned on. A bind mount from the host is then refused unless it is relabeled for container use. Add `:Z` for a volume used by one container, or `:z` for one shared by several:

```bash
podman run -d -v /srv/appdata:/data:Z docker.io/library/nginx
```

Never use `:Z` on a system directory such as `/home` or `/etc`: it relabels the whole tree for that container.

## Last resort: a local policy module

When no label, port or boolean fits, generate a small module from the denials:

```bash
sudo ausearch -c 'myapp' --raw | audit2allow -M local-myapp
cat local-myapp.te                     # read every allow rule before loading it
sudo semodule -i local-myapp.pp
```

Read the `.te` file. If it grants your app access to `shadow_t` or `user_home_t`, the fix belongs elsewhere: relabel the files instead. Remove the module with `sudo semodule -r local-myapp`.

## If you must turn it off

On RHEL 9 and 10 and their rebuilds, Red Hat documents the `selinux=0` kernel parameter as the supported way to disable SELinux. Setting `SELINUX=disabled` in the config file no longer switches it off cleanly. Permissive mode is almost always the better choice, because it keeps labeling files.

```bash
sudo grubby --update-kernel ALL --args selinux=0       # disable at the next boot
sudo grubby --update-kernel ALL --remove-args selinux  # undo it later
```

Files created while SELinux was off have no labels. To come back safely, set `SELINUX=permissive` in `/etc/selinux/config`, run `sudo fixfiles -F onboot` to relabel the file system at the next boot, reboot, check the log for denials, and only then switch to enforcing.

Practice on a server you can throw away: an AlmaLinux or Rocky Linux image on an hourly-billed CloudSat [Cloud VPS](https://cloudsat.io/cloud-vps) costs a few cents to break, inspect and delete.

## FAQ

### How do I know a failure is caused by SELinux at all?

Look for an AVC denial with a timestamp that matches the failure. If there is none, run `sudo setenforce 0`, retry once, and set it back with `sudo setenforce 1`. If the app still fails in permissive mode, the cause is elsewhere.

### Is permissive mode fine for production?

No. It logs what would have been blocked but blocks nothing. Use it for a short test, or make a single domain permissive with `semanage permissive -a` while you fix its labels.

### Do Ubuntu and Debian use SELinux?

Not by default. They ship AppArmor, which confines programs by path instead of by label. `sudo aa-status` shows which profiles are loaded and in which mode.

### Does SELinux slow a server down?

The checks add a small amount of kernel work per access, and the decisions are cached. On typical web, database and container hosts the overhead is not what limits performance, so measure your own workload before you consider any trade.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in Security](https://cloudsat.io/learn/topic/server-security)

- [Linux server hardening: audit what you already run](https://cloudsat.io/learn/linux-server-hardening-audit): Security Linux server hardening: audit what you already run 7 min read
- [Change the SSH port without locking yourself out](https://cloudsat.io/learn/change-ssh-port-safely): Security Change the SSH port without locking yourself out 7 min read
- [UFW, firewalld or nftables: choosing a Linux server firewall](https://cloudsat.io/learn/ufw-firewalld-nftables-compared): Security UFW, firewalld or nftables: choosing a Linux server firewall 7 min read
- [Harden a Windows Server VPS: RDP, accounts and updates](https://cloudsat.io/learn/harden-a-windows-server-vps): Security Harden a Windows Server VPS: RDP, accounts and updates 6 min read
