How to Disable SELinux: A Step-by-Step Guide

disable selinux

SELinux, or Security-Enhanced Linux, is a Linux kernel security module that provides access control security policies. It is designed to prevent unauthorized access to sensitive files and resources on a Linux system. Though SELinux is a powerful tool for enhancing system security, there may be situations where it needs to be disabled. In this article, we will discuss how to disable SELinux on a Linux system.

Why Disable SELinux?

There are several reasons why you might want to disable SELinux on your Linux system. Some of these reasons include:

  • SELinux may be interfering with the normal operation of a program or service.
  • You may be testing or debugging a program and need to temporarily disable SELinux to rule it out as a possible cause of the issue.
  • You may be running an application that is not compatible with SELinux.
  • You may be using a third-party security tool that conflicts with SELinux.

How to Check if SELinux is Enabled

Before disabling SELinux, it is important to check if it is currently enabled on your system. You can do this by running the following command:

sestatus

If SELinux is enabled, the output will look something like this:

SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

If SELinux is disabled, the output will look like this:

SELinux status:                 disabled

How to Temporarily Disable SELinux

If you need to temporarily disable SELinux to troubleshoot an issue or perform a specific task, you can do so by changing the SELinux mode to permissive. In permissive mode, SELinux will log policy violations but will not enforce them. To change the SELinux mode to permissive, run the following command:

setenforce 0

To verify that SELinux is now in permissive mode, run the sestatus command again. The output should show that the current mode is permissive.

SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

To change SELinux back to enforcing mode, run the following command:

setenforce 1

How to Permanently Disable SELinux

If you need to permanently disable SELinux on your Linux system, you can do so by editing the SELinux configuration file. The SELinux configuration file is located at /etc/selinux/config. Open this file in your preferred text editor and look for the following line:

SELINUX=enforcing

Change enforcing to disabled:

SELINUX=disabled

Save and close the file. You will need to reboot your system for the changes to take effect.

Conclusion

SELinux is a powerful tool for enhancing system security, but there may be situations where it needs to be disabled. In this article, we discussed how to check if SELinux is enabled, how to temporarily disable SELinux, and how to permanently disable SELinux. It is important to note that disabling SELinux can potentially leave your system vulnerable to security threats, so it should only be done if absolutely necessary.