How to disable SELinux on CentOS

Are you troubleshooting your Linux system, but SELinux is getting in the way? Here's how to disable SELinux on CentOS temporarily and permanently.

SELinux (Security-Enhanced Linux) is a security module integrated into the Linux system that provides a system administrator an ability to have more control over the system access, security policies, including MAC (Mandatory Access Control). It limits or restricts programs, and cron jobs ability to access files, what actions they can perform by defining a security policy.

SELinux protects against misuse and unauthorized access as it:

  • Restricts reading data and programs
  • Restricts modifying data and programs
  • Stops any program who try to bypass the security mechanism
  • Restricts interfering with another process
  • Prevents information security lapses

SELinux service is enabled by default when you install CentOS. Some applications may not be supporting this security mechanism, and so to make these applications work, we may need to disable or turn off SELinux. In this article, we will show you step by step procedure of disabling SELinux temporarily or permanently.

Check SELinux Status

Before we make any change to the SELinux service, we first need to check the current status of SELinux. We can do that using below command:

$ sestatus

check SELinux status
check SELinux status

After checking the status, we need to disable SELinux. It can be disabled temporarily or permanently as you wish.

Disable SELinux Temporarily

To disable SELinux temporarily,  use the following command:

# 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

This method will only disable SELinux temporarily until the next reboot. It comes in handy when you want to disable SELinux for the troubleshooting session you are in. When done with fixing, you can reboot the system, so that stays protected.

Disable SELinux Permanently

To permanent disable SELinux, let’s open the config file in the path ‘/etc/sysconfig/selinux’ and edit it using Vi editor.

# vi /etc/sysconfig/selinux

disable selinux by changing file
disable SELinux by changing file

Carefully, change the directive SELinux=enforcing to SELinux=disabled as shown in the below image.

disable selinux by changing status
disable SELinux by changing the status

Now save and exit the file.  Finally, reboot system for changes to take effect, and recheck the SELinux status to confirm.

$ sestatus

check SELinux status after reboot
check SELinux status after reboot

Conclusion

That’s all about disabling SELinux temporarily and permanently. We hope you enjoyed this short tutorial.  Do you perform system administration activities? When did you feel SELinux is on your way and had to disable it? Please leave a comment below mentioning your situation so that our readers can learn from it. Sharing is caring!

Habib Ahmed
He is a professional writer with more than seven years of experience in the field. He also enjoys technical writing/ manuals, white papers, and scientific presentations.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,272FansLike
385FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

MUST READ

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

The 10 Best Linux Network Monitoring Tools

Having total control over your network is essential to prevent programs from overusing your network resources and slowing down the overall performance. This is why you should install a network monitoring tool on your system, giving you a visual overview of everything that's happening on your network. Networking Tools are like swiss-knife for the system administrators for troubleshooting system issues.

The 10 Best Programming Languages for Hacking

One of the significant entities we have in Cyber Security is Ethical Hacking (ETH). It is the process of detecting and finding flaws or vulnerabilities in a system that a hacker would exploit.

10 Top Reasons to Switch to Manjaro Linux

Manjaro is Linux distro based on Arch-Linux which follows a rolling release model. Is this distro good for you? Let's find out the main reasons for using Manjaro.

13 ways to use the copy command in Linux (with examples)

Being a Linux user, copying files and directories is one of the everyday tasks that you have to carry out. It can be copying a file to make a backup or copy it to another partition, directory, or external storage drive.