54

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?

2
  • 4
    setenforce 0 <- did you run it from root or with sudo?
    – UVV
    Aug 7, 2014 at 6:51
  • 1
    @UVV yes i am doing all this from root Aug 7, 2014 at 13:01

6 Answers 6

67

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.

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

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.

11

On CentOS 7:

echo 0 > /sys/fs/selinux/enforce
3
  • 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, 2016 at 3:23
  • This only disables selinux in current "session" and when rebooting this config will be lost.
    – EAmez
    Mar 4 at 8:39
  • By current "session" I mean current runtime. Also 0 does not disable selinux but configure it as permissive.
    – EAmez
    Mar 4 at 8:50
7

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.

6

Best way to disable SELinuxis by using following command:

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

OR

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

OR

setenforce 0 && sestatus

Though in certain cases restart will be required.

3

For CentOS 6 (not 7):

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

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