SELinux, which stands for Security Enhanced Linux, is an extra layer of security control built for Linux systems. The original version of SELinux was developed by the NSA. Other key contributors include Red Hat, which has enabled it by default in their own RHEL and its derivative Linux distributions.
Although SELinux can protect our system through access control for programs and system services, it's not always necessary to have it enabled. Some users may even find that it interferes with certain programs they try to install. Certain distributions also have their own recommended alternative to SELinux. For example, Ubuntu uses AppArmor, which should be used instead of SELinux. In this guide, we'll go over the step by step instructions to disable SELinux on all major Linux distributions.In this tutorial you will learn:
- How to check the status of SELinux
- How to put SELinux in permissive mode
- How to disable SELinux
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
How to check the status of SELinux
You can check the current status of SELinux at any time by executing the following command.
On our test system, the screenshot above indicates that the "current mode" of SELinux is enforcing.
An even easier way to quickly check the status is with the
getenforce command, which will only output the current mode of SELinux and nothing else.
$ getenforce Enforcing
SELinux has three possible modes that you could see when running the command. They are:
- Enforcing - SELinux is active and enforcing its policy rules.
- Permissive - SELinux permits every thing, but logs the events it would normally deny in enforcing mode.
- Disabled - SELinux is not enforcing rules or logging anything.
How to disable SELinux
Depending on your needs, disabling SELinux could involve either changing it to permissive mode, or disabling it entirely.
Setting SELinux to permissive mode will disable all aspects of SELinux except for logging messages. We don't need to reboot our system for this change to take effect, and we can make the change by executing the following command.
$ sudo setenforce 0
You can verify the change by checking SELinux current mode again, either with the
When you reboot the system, SELinux will change back to enforcing mode. If you'd like the change to be permanent, you can use the following step by step instructions to disable SELinux completely or keep it in permissive mode.
- Use nano or your favorite text editor to open the SELinux configuration file located in
/etc/selinux/config. You'll need to do this with the root account or sudo command.
$ sudo nano /etc/selinux/config
- Change the
SELINUX=enforcingline to either "permissive" or "disabled", depending on the setting you prefer. Then, exit this file after saving your changes to it.
- Once you reboot the system, SELinux will be totally disabled. To avoid restarting now, execute the
setenforce 0command as explained above to get instant results while you wait till the next reboot.
In this guide, we saw how to disable SELinux on an major Linux distributions, both by setting the current mode to permissive, and by disabling SELinux completely. SELinux is a helpful feature that should only be disabled with prior consideration, or in test environments. Some distributions also have their own recommended alternative to SELinux, for example Ubuntu uses AppArmor. In such a case, SELinux can be safely disabled in favor of the distro's own security software.