To disable SELinux on CentOS, RHEL, or Fedora, you must edit the /etc/selinux/config file and set SELINUX=disabled, then reboot. This permanently turns off SELinux enforcement; a temporary disable (until reboot) is done with sudo setenforce 0, but the setting reverts on reboot unless you also change the config file.
What SELinux Actually Does
SELinux (Security-Enhanced Linux) is a mandatory access control (MAC) system built into the Linux kernel. Unlike traditional Unix permissions (DAC), where the owner decides who can access a file, SELinux enforces system-wide policies that apply to every process and file. It labels every process and file with a security context, and the kernel checks these labels on every access attempt, denying anything not explicitly allowed by the loaded policy.
On CentOS, RHEL, and Fedora, SELinux is enabled by default in enforcing mode. This means it actively blocks unauthorized actions and logs them to /var/log/audit/audit.log. There are three modes:
- Enforcing: SELinux is active and denies actions that violate policy.
- Permissive: SELinux logs violations but does not deny them.
- Disabled: SELinux is completely turned off; no labeling or checks occur.
Why People Disable It
The most common reason to disable SELinux is that it blocks a service or application that isn’t configured with the correct SELinux policy. Typical examples:
- Custom web server setups that need to write to directories outside the default
/var/www. - Third-party applications that expect to bind to non-standard ports or access unusual file locations.
- Network services like NFS or Samba that fail with “permission denied” even though file permissions look correct.
In many cases, the issue can be fixed by adjusting SELinux booleans (e.g., setsebool -P httpd_can_network_connect 1) or by setting the correct file context (e.g., semanage fcontext -a -t httpd_sys_content_t "/srv/web(/.*)?"). But when an application is not SELinux-aware and there is no time to debug, disabling SELinux becomes the quickest path.
How to Disable SELinux Permanently
Follow these steps to disable SELinux on CentOS, RHEL, or Fedora:
- Check the current status with
getenforce(should printEnforcingorPermissive). - Open the config file with root privileges:
sudo vi /etc/selinux/config(or use nano). - Change the line
SELINUX=enforcingtoSELINUX=disabled. - Save the file and reboot:
sudo reboot. - After reboot, verify with
getenforce— it should outputDisabled.
Note: On some modern Fedora systems, the config file path is /etc/selinux/config as well, but the file may be symlinked. The same edit applies.
Temporary Disable (No Reboot)
If you need to test whether SELinux is the cause of a problem, you can switch to permissive mode without a full reboot:
sudo setenforce 0
This sets SELinux to permissive until the next reboot. To re-enable enforcement, use sudo setenforce 1. This is useful for troubleshooting because it lets you see if the application works with SELinux in permissive mode. If it does, you can then decide whether to fix the policy or disable SELinux permanently.
Common Pitfalls and What to Avoid
- Don’t just set
setenforce 0and forget it — after reboot, SELinux will be enforcing again, and the problem may return. - Don’t disable SELinux on a system that handles sensitive data — SELinux provides an extra layer of defense against compromised processes. Removing it increases risk.
- Don’t use
selinux=0in the kernel command line unless you have a specific reason; it disables SELinux only for that boot, and it can cause confusion. - Don’t change the mode to
disabledon a system that is already running with SELinux enforcing without a reboot — the change takes effect only after reboot.
Alternatives to Disabling SELinux
Before you disable SELinux, consider these safer alternatives:
- Set to permissive: This logs violations without blocking, letting you see what is being denied. You can then use
audit2whyto suggest fixes. - Adjust booleans: Many common issues are solved by flipping a boolean. For example, to allow Apache to make network connections:
setsebool -P httpd_can_network_connect 1. - Change file contexts: If a service needs to read a file outside its usual location, you can set the correct context with
semanage fcontextand thenrestorecon. - Create a custom policy module: For complex cases, you can generate a custom policy using
audit2allow -M mymoduleand then install it withsemodule -i mymodule.pp.
These methods keep SELinux active, which is generally recommended for production systems.
Frequently Asked Questions
Is it safe to disable SELinux?
Disabling SELinux removes a security layer, but for a home server or a test environment, the risk may be acceptable. For production systems, it is safer to fix the policy or run in permissive mode temporarily.
Can I disable SELinux without rebooting?
You can switch to permissive mode without a reboot using setenforce 0, but to completely disable SELinux you must edit the config file and reboot. There is no way to fully disable SELinux without a reboot.
Why does my service still fail after disabling SELinux?
If the problem persists after disabling SELinux, it is likely not caused by SELinux. Check file permissions, firewall rules (firewalld/iptables), or the service’s own configuration.
How do I re-enable SELinux after disabling it?
Edit /etc/selinux/config and set SELINUX=enforcing (or permissive), then reboot. Note that if you have been running with SELinux disabled for a while, you may need to relabel the filesystem: touch /.autorelabel before reboot.
What is the difference between permissive and disabled?
In permissive mode, SELinux still labels files and processes and logs violations, but does not block them. In disabled mode, SELinux is completely inactive, and no labels are applied. Disabled is a more drastic change and can affect file labels if you later re-enable.
Does disabling SELinux affect performance?
Disabling SELinux can slightly improve performance because the kernel skips the access checks, but the difference is usually negligible on modern hardware. The main impact is security, not speed.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Gadgets After Support Ends: Do They Improve?
- Delete Google Search Results About You
- OnePlus Buds Pro 3 Price Drop: Are They Worth It?
- Cloud Migration Ways to Prepare
- Remote Work Productivity Hacks That Actually Work
- Epic Games Removes Dark and Darker? Fact Check