← All articles

Disable SELinux

How to disable SELinux, understand the security implications, and troubleshoot common problems while keeping SELinux protection enabled.

Commands prefixed with sudo require administrative privileges. If you are already working in a root shell, omit sudo. Commands shown without sudo can normally be run as an ordinary user, although access may depend on the system configuration.

SELinux can be disabled by adding selinux=0 to the kernel command line and rebooting. On RHEL 8, 9 and 10, and compatible systems using grubby, the steps are:

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

After the restart, check the result with getenforce. It should report Disabled.

Before you do this: disabling SELinux removes its mandatory access control protection for the whole system and makes troubleshooting denials harder. If an application is not working, a narrower exception or a configuration correction is usually a better place to start. This article explains both the command and those alternatives.

These examples target RHEL and compatible distributions such as AlmaLinux and Rocky Linux; verify your version, bootloader and local policy before applying them. Commands that change system security or reboot a machine should be planned appropriately, especially on production systems.

Permissive mode is not the same as disabled

SELinux has three main states:

StatePolicy enforcementSELinux denial logging
EnforcingEnabled, except for domains individually marked permissiveDenials are normally logged, subject to policy and audit configuration
PermissiveNot enforced system-wideDenials are normally logged, subject to policy and audit configuration
DisabledSELinux infrastructure is disabledSELinux does not generate AVC denials

To temporarily stop system-wide enforcement without a reboot:

sudo setenforce 0
getenforce

The second command should report Permissive. Return to enforcing as soon as the investigation is complete:

sudo setenforce 1
getenforce

setenforce changes the current runtime mode; it does not change the configured mode for the next boot. System-wide permissive mode removes SELinux enforcement from every domain, so use it only for a controlled, short investigation. If SELinux is disabled, setenforce cannot enable it. Consider a permissive domain first, as described below.

How to disable SELinux permanently

On RHEL 8, 9 and 10, you can use the grubby method shown above. It changes the boot configuration for all installed kernels; the change takes effect after reboot. Check the kernel command line after reboot with cat /proc/cmdline, as well as the status with getenforce.

On RHEL 8, setting SELINUX=disabled in /etc/selinux/config is a deprecated alternative. Disabling at runtime this way can cause kernel problems. On RHEL 9, changing that setting alone does not fully disable the SELinux infrastructure. Avoid assuming that instructions for RHEL 7 or older CentOS releases apply to current systems. See RHEL 8, RHEL 9 and RHEL 10 documentation for version-specific details.

Why disabling SELinux matters

Disabling SELinux removes a layer of mandatory access control (MAC) that works alongside traditional Linux user, group and file permissions. What you lose depends on your policy and configuration, but the consequences can include:

  1. Loss of process confinement. SELinux can restrict a service to the resources and operations its domain needs, even when ordinary Unix permissions would allow more. For example, a properly confined web server can be prevented from reading SSH keys or unrelated files. The actual protection depends on the active policy, labels and the process domain.

  2. Less protection against privilege escalation. SELinux policy can limit what a compromised process is allowed to do, including operations that might be used to gain additional privileges. Without this layer, an attacker has more opportunity to act within the permissions and capabilities available to the compromised process. Other security mechanisms can still apply.

  3. Less containment of unknown vulnerabilities. SELinux may restrict the damage caused by an exploit even before a patch is available. Its effectiveness depends on the policy and the access already granted; it cannot guarantee that every attack will be contained.

  4. Fewer restrictions on root processes. SELinux can restrict processes running as root when their domains are confined by policy. Root processes in unconfined domains may already have broad access, so the effect depends on the configuration.

  5. Potential impact on security and compliance requirements. An organization may rely on SELinux as part of its security controls or compliance approach. Disabling it can affect those controls; the applicable requirements depend on the system, organization and standard.

  6. Loss of SELinux denial records. When SELinux is disabled, it no longer generates AVC denial messages. These records can help identify policy conflicts, misconfigurations and potentially suspicious activity. Other system and audit logs may still be available.

  7. More work to re-enable protection. Files created or changed while SELinux is disabled may have missing or inappropriate labels. Re-enabling SELinux may require relabeling filesystems, which can take time and should follow your distribution’s documented procedure.

If you are troubleshooting, consider making only the affected domain permissive first. System-wide permissive mode is another temporary option: SELinux remains enabled and normally logs denials, but enforcement is suspended for the whole system. In either case, investigate the cause and return to enforcing as soon as the issue is resolved.

First, identify what is being denied

An application error does not automatically mean SELinux caused it. Check conventional file permissions, service configuration and logs as well. On a system with audit logging configured, search recent AVC and USER_AVC events:

sudo ausearch -m AVC,USER_AVC -ts recent -i

Read the event in context: the source context (scontext) identifies the process domain; the target context (tcontext), object class (tclass) and requested permission indicate what it tried to access. Correlate the timestamp and process with the failure. Some denied operations may be suppressed by dontaudit rules or not captured due to audit configuration, so no AVC does not conclusively rule out SELinux.

Fix a file-label problem

Incorrect labels are a common issue when a service uses a non-standard location or files have been moved. Inspect the current and expected contexts:

ls -ldZ /path/to/directory
matchpathcon /path/to/directory

If the policy already defines the appropriate label for that path, preview and then restore the expected context:

sudo restorecon -nRv /path/to/directory
sudo restorecon -Rv /path/to/directory

For a non-standard path, the default label might itself be unsuitable. Define a persistent file-context mapping with semanage fcontext, using the type appropriate to the service and intended access, then apply it with restorecon. Check the service’s SELinux documentation first. Avoid applying a label blindly: different types grant different access.

Check service-specific configuration and Booleans

SELinux policy often includes documented settings for supported service configurations. For example, a web server may need an appropriate Boolean for a particular network access pattern. Inspect available options and their descriptions:

getsebool -a | grep httpd

Use only the setting that matches the intended behavior, understand its security effect, and consult the applicable service policy documentation. Also check port labels and container volume labeling where relevant. A permission failure can involve ordinary permissions, SELinux labels, configuration, or a combination of these.

Troubleshoot one domain with permissive mode

If a specific confined domain still needs investigation, it can be made permissive while the rest of the system remains enforcing. First confirm the actual domain from the AVC and process context; httpd_t is only an example and may cover multiple services or processes:

ps -eZ | grep httpd

On systems with semanage available:

sudo semanage permissive -l
sudo semanage permissive -a httpd_t

Repeat only the activity needed to reproduce the problem, inspect the resulting audit events, and remove the exception once done:

sudo semanage permissive -d httpd_t
sudo semanage permissive -l

A permissive domain exception affects all processes in that domain, persists across reboots, and weakens their confinement. Record it and remove it promptly. The list may also show domains made permissive by policy rather than by a local semanage exception; removing the local exception does not override a separate policy declaration. A globally enforcing status alone does not prove every domain is enforcing.

During policy development, a policy author can instead add a permissive declaration to a domain’s policy source (.te file):

permissive httpd_t;

Here, httpd_t is an example: use the actual domain being developed or investigated. Rebuild and load the policy module for the change to take effect. This makes the exception reviewable with the policy but also carries it wherever the module is deployed. Remove the declaration, rebuild and reload the module when the investigation ends. If another permissive declaration remains active, removing just one exception will not restore enforcement.

Should you use audit2allow?

audit2allow can suggest policy rules from audit events, but a suggested rule is not necessarily a safe or correct fix. A denial may reflect a wrong label, a missing service configuration, an unnecessarily broad request, or even unwanted behavior. Investigate those possibilities first.

If a custom policy is justified, collect a narrowly scoped set of relevant events, inspect the proposed permissions, compare them with the application’s intended behavior, and test the resulting policy. Do not automatically install a module generated from an unfiltered audit log.

Re-enable SELinux after disabling it

Re-enabling SELinux requires planning, especially on a production host. On systems disabled with the grubby command above, removing the boot argument is one part of the process:

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

Before rebooting, review /etc/selinux/config and your distribution’s procedure. Use a planned permissive boot and relabel as required, verify the labels and services, and only then return to enforcing. Some systems automatically schedule relabeling when returning from a disabled state; check the procedure for your distribution and release. A relabel can take significant time; do not run a blanket forced relabel on a live system without understanding its effects and distribution-specific instructions. See the RHEL 9 or RHEL 10 guidance.

Keep the protection, solve the problem

When SELinux blocks an application, identify the denied operation and its context before changing the policy. Correct labels and supported service settings first. If deeper investigation is needed, a temporary permissive domain can preserve enforcement elsewhere. Return the affected domain to enforcing and retest the application when the underlying issue has been resolved.

← Back to all articles

Contact Info

Send us a message

Tell us about your application, infrastructure or security requirements. All fields below are required.

Protected by our own security check.