How To Enable or Reinstall SELinux on CentOS

SELinux (Security-Enhanced Linux) is a special mechanism that is responsible for kernel security. This guide will be useful for users with a CentOS 6, 7, and 8 virtual machine.

Disable and uninstall SELinux

# setenforce 0
# yum remove selinux-policy\*
# rm -rf /etc/selinux/targeted /etc/selinux/config

Install SELinux

# yum install selinux-policy-targeted
# yum install selinux-policy-devel policycoreutils
# touch /.autorelabel; reboot

SELinux will detect the /.autorelabel file upon reboot, and then reconfigure all the files in the correct SELinux contexts. If you have many files in your virtual machine, then VPS may be unavailable for a long time.


If SELinux is not already installed, then you need to go to step 2 – installing SELinux. If SELinux is installed on your virtual server, then you need to remove it (to reset the policy to the default settings)

Was this article helpful?

Related Articles

Leave A Comment?