首页 > 技术文章 > switch_selinux.sh | 开启或禁用SELinux

shichangming 2018-12-30 10:25 原文

switch_selinux.sh | 开启或禁用SELinux

#!/bin/bash
SELINUX_CFG="/etc/selinux/config"
uasge() {
        echo "Usage: $0 on|off"
        exit
}
main() {
        case "$1" in
                on)
                        sed -ri /^SELINUX=/'s/(SELINUX=).*/\1enforcing/' $SELINUX_CFG
                        ;;
                off)
                        sed -ri /^SELINUX=/'s/(SELINUX=).*/\1disabled/' $SELINUX_CFG
                        echo "you should reboot to make selinux enabled."
                        ;;
                *)
                        uasge
                        ;;
        esac
}
main $1

推荐阅读