Operating System CentOS

How to Disable SELinux or Set It to Permissive on AlmaLinux 9 and Rocky Linux 9

Switch SELinux to permissive or disable it on the RHEL 9 family, temporarily or permanently, re-enable it safely, or relax it for a single service instead.

This guide explains how to switch SELinux to permissive mode or turn it off completely on AlmaLinux 9, Rocky Linux 9, CentOS Stream 9 and RHEL 9, temporarily and permanently, and how to turn it back on safely. It also covers the option most people actually need: leaving SELinux enforcing and relaxing it for the one service that is being blocked.

CentOS 7 reached end of life in June 2024 and CentOS 6 in November 2020; neither receives security updates. On those releases you disabled SELinux by writing SELINUX=disabled to /etc/selinux/config. On the RHEL 9 family that line no longer disables SELinux fully, so the procedure has changed.

Enforcing, permissive and disabled

StateWhat happensUse it for
EnforcingPolicy violations are blocked and logged. This is the default.Normal operation
PermissiveNothing is blocked, but every violation is logged and files keep getting labels.Finding out whether SELinux causes a problem
DisabledNo policy is loaded, nothing is logged, new files are created without labels.Rare cases where a vendor requires it

Red Hat recommends permissive mode over disabling. The practical reasons: in permissive mode the audit log tells you exactly what would have been denied, so you can fix it; and files keep their labels, so going back to enforcing is one command. After a period in the disabled state the whole file system has to be relabelled before SELinux can be enforced again, and a service that was confined by policy, such as a web server that may only read its own content, runs with no such limit in the meantime.

Check the current state

getenforce

The answer is Enforcing, Permissive or Disabled. For more detail, including the mode configured for the next boot:

sestatus

Switch to permissive mode until the next reboot

sudo setenforce 0

The change is immediate and needs no restart of any service. Reproduce the problem you are investigating. If it is gone, SELinux was blocking something; if it is still there, SELinux is not the cause. Switch back with:

sudo setenforce 1

setenforce cannot disable SELinux and cannot enable it on a system that booted with it disabled; it only moves between enforcing and permissive. The old /selinux/enforce path used on CentOS 6 does not exist any more.

Make permissive mode permanent

Open the configuration file:

sudo vi /etc/selinux/config

Set the SELINUX line as follows and leave SELINUXTYPE=targeted alone:

SELINUX=permissive

Or make the same edit with one command:

sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/' /etc/selinux/config

The file is read at boot, so also run sudo setenforce 0 to change the running system, or reboot. /etc/sysconfig/selinux, which older tutorials tell you to edit, is a symbolic link to this file. Edit /etc/selinux/config directly: some editors and sed -i replace a symlink with a regular file, after which the change is silently ignored.

Disable SELinux completely

On the RHEL 9 family, the documented way is a kernel command-line parameter. If SELinux is disabled only through SELINUX=disabled in /etc/selinux/config, the kernel still starts with SELinux enabled and then runs with no policy loaded, which is not the same as off and still costs some resources.

Add selinux=0 to the boot entries of all installed kernels:

sudo grubby --update-kernel ALL --args selinux=0

Reboot:

sudo reboot

Verify after the restart:

getenforce

The output is Disabled. Kernels installed by later updates inherit the parameter. grubby is part of a standard installation; if the command is missing, install it with sudo dnf install grubby.

Turn SELinux back on

Files created while SELinux was disabled have no labels, and an enforcing system with unlabelled files may fail to boot or to start services. Go through permissive mode first.

Set permissive mode in the configuration file:

sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/' /etc/selinux/config

Remove the kernel parameter:

sudo grubby --update-kernel ALL --remove-args selinux

Schedule a full relabel for the next boot and restart. The relabel can take from a minute to much longer on a server with many files; do not interrupt it.

sudo fixfiles -F onboot
sudo reboot

After the reboot, look for denials that would have been enforced:

sudo ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent

When the list is empty or explained, set SELINUX=enforcing in /etc/selinux/config and reboot once more, or run sudo setenforce 1 to enforce immediately.

Better: relax SELinux for one service only

If one application is being blocked, you do not have to give up protection for the whole server.

Find out what is denied

sudo ausearch -m AVC -ts recent

For explanations in plain language, install the troubleshooting tools and let them analyse the audit log:

sudo dnf install setroubleshoot-server
sudo sealert -a /var/log/audit/audit.log

Most denials on a server have one of three causes: a file in a non-standard location with the wrong label (fix with semanage fcontext and restorecon), a service on a non-standard port (fix with semanage port), or an optional behaviour that is switched off by a boolean (fix with setsebool -P). The sealert output names the matching command.

Make a single domain permissive

When you need a service to work now and want to sort out the policy later, put only its domain in permissive mode. The semanage tool comes from this package:

sudo dnf install policycoreutils-python-utils

Find the domain the process runs in. For the Apache web server, for example:

ps -eZ | grep httpd

The third field of the label, here httpd_t, is the domain. Make it permissive:

sudo semanage permissive -a httpd_t

The rest of the system stays enforcing, and denials for that domain are still logged. List permissive domains and remove the exception again with:

sudo semanage permissive -l
sudo semanage permissive -d httpd_t

Boot parameters for emergencies

If a system does not boot because of SELinux, you do not need to change any file. In the GRUB menu, press e on the boot entry, append one of these to the line starting with linux, and press Ctrl+X:

  • enforcing=0 boots in permissive mode for this one start.
  • selinux=0 boots with SELinux disabled for this one start.
  • autorelabel=1 forces a relabel of the file system during this boot.

Prefer enforcing=0: it gets you a working system and a log of the denials without creating unlabelled files.

The full procedures are in Red Hat's Using SELinux: Changing SELinux states and modes, which applies unchanged to AlmaLinux, Rocky Linux and CentOS Stream 9.

Frequently asked questions

Do I need to reboot to disable SELinux?

To disable it fully, yes: the kernel decides at boot whether SELinux is on. To stop it from blocking anything right now, sudo setenforce 0 is enough and takes effect immediately.

An installer says SELinux must be disabled. What should I do?

Try permissive mode first. Most installers that make this demand only need SELinux not to block them, and many only check the output of getenforce. If the software's own documentation insists on Disabled, use the grubby method, and check whether a current release of that software still has the requirement; many control panels and applications now ship SELinux policy of their own.

Does SELinux slow the server down?

Access decisions are cached in the kernel, and for ordinary web, database and mail workloads the overhead is small enough that it is rarely a reason to disable SELinux. If you have a measured performance problem, compare enforcing against selinux=0 under your own load before deciding.

Is the procedure the same on RHEL 10, AlmaLinux 10 and Rocky Linux 10?

Yes. setenforce, /etc/selinux/config for permissive mode and the selinux=0 kernel parameter for disabling work the same way on the 10 releases.

Share story:

Continue reading other guides on How VPS.