How to Disable SELinux Temporarily or Permanently in RHEL/CentOS 7/6?

Because of illustrious security implementation features such as SELinux (Security-Enhanced Linux), Linux is regarded as one of the most secure Operating Systems. SELinux is described as a mandatory access control (MAC) security structure executed in the kernel. SELinuxoffers a means of enforcing some security policies which would otherwise not be effectively implemented by a System Administrator.

When you install RHEL/CentOS or several derivatives, the SELinux feature or service is enabled by default, due to this, some applications on your system may not actually support this security mechanism. Therefore, to make such applications function normally, you have to disable or turn off SELinux.

Important: If you don’t want to disable SELinux, then you should read the following articles to implement some mandatory access control on files and services to function properly. 

 First of all, we need to check the status of SELinux on your system, for that run the following command:

$ sestatus

Now, proceed to disable SELinux temporarily or permanently depending on your specification.

Disable SELinux Temporarily

To disable SELinux temporarily, issue the command below as root:

# echo 0 > /selinux/enforce

Alternatively, you can use the setenforce tool as follows:

# setenforce 0

Else, use the Permissive option instead of 0 as below:

# setenforce Permissive

These methods above will only work until the next reboot, therefore to disable SELinux permanently, move to the next section.

Disable SELinux Permanently

To permanently disable SELinux, use your favorite text editor to open the file /etc/sysconfig/selinux as follows:

# vi /etc/sysconfig/selinux

Then change the directive from SELinux=enforcing to SELinux=disabled.

SELinux=disabled

Then, save and exit the file, for the changes to take effect, you need to reboot your system and then check the status of SELinux using sestatus command as shown:

$ sestatus

That's it

Was this answer helpful? 0 Users Found This Useful (0 Votes)