How to Disable SELinux
You have setup a new system, or installed something new on the Your Linux system and its not working. You get the feeling-SELinux is the cause of the problem. This page is written to help.
Contents
Overview
Should you really disable SELinux?
Temporarily switch off enforcement
Permanently Permissive
Fully disabling SELinux
Re-enabling SELinux
Overview
SELinux has the major components on your system. There ' s the kernel mechanism which is enforcing a bunch of access rules which apply to processes and files. and secondly, there ' s file Labels: every file on your system have extra labels attached to it which tie-in with T Hose access rules. Run ls-z and you'll see what I mean.
Should you really disable SELinux?
Be aware this by disabling SELinux you'll be removing a security mechanism on your system. Think about this carefully, and if your system are on the Internet and accessed by the public, then Think about it some mor E. Joshua Brindle (an SELinux developer) have comments on disabling selinux here, which states clearly that applicatio NS should is fixed to work with SELinux, rather than disabling the OS security mechanism.
You need to decide if Y ou want to disable SELinux temporarily to test the problem, or permanently switch it off. It may also is a better option to do changes to the policy to permit the operations that is being blocked-but this re Quires knowledge of writing policies and May is a steep learning curve for some people. For the operating system as a whole, there is the kinds of disabling:
- Permissive -Switch the SELinux kernel into a mode where every operation is allowed. Operations that would being denied is allowed and a message is logged identifying the it would be denied. The mechanism, defines labels for files which was being created/changed is still active.
- Disabled -SELinux is completely switched off in the kernel. This allows all operations to being permitted, and also disables the process which decides what to label files & Processe S with.
Disabling SELinux could leads to problems if you want to re-enable it again later. When the system runs with file labelling disable it would create files with no Label-which could cause problems if the SY Stem is booted into enforcement mode. A full re-labelling of the file system would be necessary.
Temporarily switch off enforcement
You can switch the system to permissive mode with the following command:
echo 0 >/selinux/enforce
You'll need to being logged in as root, and in the Sysadm_r role:
Newrole-r Sysadm_r
To switch back into enforcing mode:
Echo 1 >/selinux/enforce
In Fedora Core and RedHat Enterprise Linux You can use the setenforce command with a 0 or 1 option to set Permiss Ive or enforcing mode, its just a slightly easier command than the above.
To check what mode of the system is in,
Cat/selinux/enforce
Which would print a "0" or "1" for permissive or enforcing-probably printed at the beginning of the command p Rompt.
Permanently Permissive
The above would switch off enforcement Temporarily-until you reboot the system. If you want the "system to always start" in permissive mode, then here's how it.
In Fedora Core and RedHat Enterprise, edit /etc/selinux/config and you'll see some lines like this:
# This file controls the state of SELinux in the system.# selinux= can take one of the these three values:# Enforcing-selinu X security Policy is enforced.# permissive-selinux prints warnings instead of enforcing.# disabled-no SELinux policy I s loaded. selinux=enforcing# selinuxtype= can take one of these, values:# targeted-only targeted network daemons is P rotected.# Strict-full SELinux Protection. selinuxtype=targeted
... just change selinux=enforcing to selinux=permissive, and you ' re-done. Reboot if you want to prove it.
For the other linuxes which don ' t has the /etc/selinux/config file, you just need to edit the kernel boot line, Usually in /boot/grub/grub.conf if you ' re using the Grub boot loader. On the kernel line, add enforcing=0 at the end. For example,
enforcing=0#initrd/boot/initrd-2.4.20-selinux-2003040709.img
Fully disabling SELinux
Fully disabling SELinux goes one step further than just switching into permissive mode. Disabling would completely disable all SELinux functions including file and process labelling.
In Fedora Core and RedHat Enterprise, edit /etc/selinux/config and change the SELinux line toselinux=disabled :
# This file controls the state of SELinux in the system.# selinux= can take one of the these three values:# Enforcing-selinu X security Policy is enforced.# permissive-selinux prints warnings instead of enforcing.# disabled-no SELinux policy I s loaded. selinux=disabled# selinuxtype= can take one of these, values:# targeted-only targeted network daemons are PR otected.# Strict-full SELinux Protection. selinuxtype=targeted
... and then reboot the system.
For the other linuxes which don ' t has the /etc/selinux/config file, you just need to edit the kernel boot line, Usually in /boot/grub/grub.conf, if you ' re using the Grub boot loader. On the kernel line, add selinux=0 at the end. For example,
Title Se-linux Test System root (hd0,0) selinux=0 #initrd/boot/ Initrd-2.4.20-selinux-2003040709.img
You'll have to reboot to disable SELinux, and you just can ' t do it while the system is running.
Re-enabling SELinux
If you've disabled SELinux as in the sections above, and you want to enable it again then you've got a bit of work to do. The problem'll be, that files created, or changed when SELinux is disabled won ' t has the correct file labels on them-i f you just reboot in enforcing mode then a lot of stuff won ' t work properly.
What are need to be to enable SELinux by editing /etc/selinux/config (for fedora/redhat) or by addingSelin Ux=1 to the kernel boot line, then boot into permissive mode, then relabel everything, and then reboot into (or simply switch to) enforcing mode.
After booting into permissive mode, runfixfiles relabel
Alternatively, in Fedora and RedHat Enterprise Linux can runtouch/.autorelabeland reboot or putAutorelab Elon the boot command line-in both cases the file system gets a full relabel early in the boot process. Note that this can take quite some time to systems with a large number of files.
After relabelling the filesystem, you can switch to enforcing mode (see above) and your system should be fully enforcing a Gain.
[ZZ] How to Disable SELinux