How to Disable Selinux on CentOS 7

Security is an essential element of server management. However, personal or small projects can sacrifice certain aspects of security. In the case of Linux distributions, many of them already have strong security policies. In particular, CentOS 7 and RHEL, are profiled as the most reliable security options throughout Linux thanks to SELinux multi level security protection.

However, sometimes too many security policies can hinder some day-to-day and community tasks. That is why it is sometimes necessary to disable certain measures. In this post, we will teach you how to disable SELinux in CentOS 7.

What is SELinux?

SELinux on the system you installed is a security control feature that restricts access to specific Kernel modules. CentOS 7 and RHEL implement it by default to provide an extra layer of security for the system. However, it can be implemented in other Linux distributions such as Debian.

SELinux is managed through certain rules called “policies” that restrict or allow the use of certain applications for essential parts of the system. The problem is that making these policies is very hard.

SELinux currently has three states:

  • The Enforcing state denies all unauthorized access. In this state, we refer to it as SELinux enabled
  • In Permissive SELinux prints warnings. Unlike the first state, this state allows unauthorized access but shows a warning
  • Disable SELinux state means the feature is off and allows all access without warnings

Now that we know how SELinux works, we know if it’s worth disabling.

Disabling SELinux

It is possible to disable SELinux temporarily or permanently. Each has its own advantages. Doing it temporarily will allow us to test without sacrificing the security of the system. Once the system is restarted, SELinux will be activated again.

On the other hand, if we deactivate SELinux permanently, we will be able to work faster especially if it is a personal or medium sized project. We must bear in mind that, at this point, most Linux distributions have very good security policies so we can afford it.

In this post, we will teach you how to do it both ways.

Disable SELinux Temporarily on CentOS 7

First, we need to access the server using SSH. If you have any questions about how to do it, check out our SSH tutorial! Run the following command:

ssh your-user@your-server

On the other hand, if we are using CentOS on our personal computer, we just need to open the terminal.

After that, we have to verify the status of SELinux. It is quite simple and we can do it with the following command:


In the output we will be notified that, SELinux is enabled with the enforcing state.

To disable it temporarily we just run the following command:

setenforce 0

Now, we need to check the SELinux status again.

The output will show that SELinux is now in permissive mode, meaning we can use the system easily.

As it is temporarily disabled, changes will be made automatically, at the time of restart, when SELinux is restarted. The main advantage of this method is that it is not necessary to reboot the system.

Disable SELinux permanently on CentOS 7

To permanently disable SELinux, we’ll need need to edit a configuration file.

First, let’s install the nano text editor:

yum install nano

After that, we need to edit the selinux configuration file.

nano /etc/sysconfig/selinux
Selinux configuration file opened on nano in centos 7

We will edit the value of SELINUX. The file is very descriptive and shows the different values we can assign. In other words, the different states that SELinux can take.
In this case, to disable it completely, we have to set the value to Disabled.


Then, we have to save the file by hitting CTRL+O and close it with CTRL+X. For all this to work, we need to reboot the system, and then we can check if the update worked by executing this command in the command line:


This we will have disabled SELinux in CentOS 7.


SELinux is a great security tool for CentOS 7. However, for some people, it can be a bit annoying and inconvenient. When considering to disable a security layer always think if it is a risk you’re willing to take.

In this post, we overview how to disable SELinux temporarily and permanently, according to the needs we may have. We hope you found this tutorial helpful!

About the author

Edward S.

Edward is Hostinger's copywriter. He's an expert communicator with years of experience in IT as a writer, marketer, and Linux enthusiast. IT is a core pillar of his life, personal and professional. Edward's goal is to encourage millions to achieve an impactful online presence. He also really loves dogs, guitars, and everything related to space.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in VPS
What is a Chown Command in Linux and How to Use it