I need to disable SELinux but cannot restart the machine

i followed this link where i get bellow command

setenforce 0

But after running this command i checked for that

sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   permissive
Mode from config file:          disabled
Policy version:                 24
Policy from config file:        targeted

Is there any other option?

  • 3
    setenforce 0 <- did you run it from root or with sudo? – UVV Aug 7 '14 at 6:51
  • 1
    @UVV yes i am doing all this from root – Vikas Hardia Aug 7 '14 at 13:01
up vote 49 down vote accepted

sestatus is showing the current mode as permissive.

In permissive mode, SELinux will not block anything, but merely warns you. The line will show enforcing when it's actually blocking.

I don't believe it's possible to completely disable SELinux without a reboot.

  • I think you can disable it without a reboot by directly editing the /etc/selinux/config file and setting SELINUX=disabled – dmohr Mar 2 at 19:40
  • @dmohr - If you read this Centos document it tells you that it only works on the next reboot. – garethTheRed Mar 2 at 19:50

On CentOS 7:

echo 0 > /sys/fs/selinux/enforce
  • 2
    fwiw, this didn't work for me, Centos 7.2: # sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: permissive # echo 0 > /sys/fs/selinux/enforce # sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted – datakid Oct 4 '16 at 3:23

Disabling SELinux without reboot is not possible. But I guess making it in permissive mode is going to satifsy your requirement.

The output of sestatus shows SELinux is enabled but also shows it is in Permissive mode, which is what you just did with the setenforce command.

At the time of writing what OP did should work. On Fedora 26:

[aries@csibesz]$ sestatus
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:      30

As user doesn't work.

[aries@csibesz]$ setenforce 0
setenforce:  setenforce() failed

As root, it does:

[aries@csibesz]$ sudo setenforce 0
[aries@csibesz]$ sestatus
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:      30

The same applies to CentOS 7 and RedHat EL 7: it is working without reboot.

Best way to disable selinux is by using following command:

  1. sed -i 's/enforcing/disabled/g' /etc/selinux/config /etc/selinux/config

OR

  1. vi /etc/sysconfig/selinux, set selinux=disabled

OR

  1. set enforce 0 sestatus

Though in certain cases restart will be required.

For CentOS 6 (not 7):

echo 0 > /selinux/enforce
  • 1
    Does not work on centos 7. Only works on centos 6 and under – shreddd Oct 19 '16 at 19:35
  • 1
    This answer is correct for centos 6. Please double check before downvoting. – ora-600 Jun 12 '17 at 16:07

I have been having the similar problems with SELinux (using Fedora 27) and used the last item above:

  1. set enforce 0 sestatus reboot

I now get the following message:

[ibrinks@ibrinks-linux ~]$ sestatus SELinux status: disabled

Thanks folks that improved performance substantially

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.