How to disable SElinux on CentOS 7

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, including CentOS 7.

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 tutorial, we will go over the step by step instructions to disable SELinux on CentOS 7 Linux.

In this tutorial you will learn:

  • How to check the status of SELinux
  • How to put SELinux in permissive mode
  • How to disable SELinux on CentOS 7
How to disable SElinux on CentOS 7
How to disable SElinux on CentOS 7
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System CentOS 7
Software SELinux
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to check the status of SELinux



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!


You can check the current status of SELinux at any time by executing the following command.

$ sestatus
Checking the current mode of SELinux on CentOS 7
Checking the current mode of SELinux on CentOS 7

On our CentOS 7 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 on CentOS 7 step by step instructions

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
OR
# setenforce 0

You can verify the change by checking SELinux current mode again, either with the sestatus or getenforce command.

SELinux is currently in permissive mode
SELinux is currently in permissive mode




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.

  1. 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
    
  2. Change the SELINUX=enforcing line to either “permissive” or “disabled”, depending on the setting you prefer. Then, exit this file after saving your changes to it.
    SELINUX=disabled
    
    Set the SELINUX directive to disabled to permanently disable it
    Set the SELINUX directive to disabled to permanently disable it
  3. Once you reboot the system, SELinux will be totally disabled. To avoid restarting now, execute the setenforce 0 command as explained above to get instant results while you wait till the next reboot.
    $ reboot
    
After a reboot, SELinux has been disabled completely on CentOS 7
After a reboot, SELinux has been disabled completely on CentOS 7

Closing Thoughts




In this tutorial, we saw how to disable SELinux on a CentOS 7 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.