SELinux, which stands for Security Enhanced Linux, is an extra layer of security control built into Red Hat Enterprise Linux and its derivative Linux distributions, such as CentOS. SELinux is enabled by default on CentOS 8, and would have to be manually disabled if a user doesn’t wish to use it.
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. In this guide, we’ll go over the step by step instructions to disable SELinux on CentOS 8, both temporarily or persistently across reboots.
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|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
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 everything, but logs the events it would normally deny in enforcing mode.
- Disabled – SELinux is not enforcing rules or logging anything.
By default, CentOS 8 has SELinux enabled and in enforcing mode.
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 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 CentOS 8 Linux system, 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. Still, it can cause problems in certain situations, so the developers have given us a way to disable it.