Saturday, April 6, 2013

Quickly disable SELinux in a setup script

So we all know how to disable SELinux manually, but what about doing so as part of a setup script?
Easy, got to love sed!

Setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/sysconfig/selinux && cat /etc/sysconfig/selinux
Repeat on /etc/selinux/config for Centos 7

1 comment:

  1. Since I just fell into this one:

    sed -i --follow-symlinks 's/^SELINUX=.*/SELINUX=disabled/g' /etc/sysconfig/selinux && cat /etc/sysconfig/selinux

    Otherwise sed will ignore the /etc/sysconfig/selinux --> /etc/selinux/config symlink and you will end up with two files and selinux will remain enforcing after a reboot!

    ReplyDelete