50

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?

  • 4
    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
62

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.

| improve this answer | |
  • 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 '18 at 19:40
  • 1
    @dmohr - If you read this Centos document it tells you that it only works on the next reboot. – garethTheRed Mar 2 '18 at 19:50
12

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.

| improve this answer | |
11

On CentOS 7:

echo 0 > /sys/fs/selinux/enforce
| improve this answer | |
  • 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
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.

| improve this answer | |
4

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.

| improve this answer | |
3

For CentOS 6 (not 7):

echo 0 > /selinux/enforce
| improve this answer | |
  • 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. – o0x258 Jun 12 '17 at 16:07

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