SELinux是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统。但是SELinux的并不能与众多服务很好的兼容,有些人会关闭SELinux一了百了。在日常的运维过程中很少去频繁的开启关闭SElinux,今天我就写一个关闭与开启SELinux的脚本来锻炼我的脚本能力。
#!/bin/bash # -------------+-------------------- # * Filename : selinux.sh # * Revision : 2.0 # * Date : 2017-09-02 # * Author : Aubin # * Description : # -------------+--------------------- # www.shuaiguoxia.com # path=/app/selinux selinux=`sed -rn "/^(SELINUX=).*\$/p" $path` case $1 in enforcing|en) sed -ri "s@^(SELINUX=).*\$@\1enforcing@g" $path if [ $selinux == 'SELINUX=disabled' ];then read -p "SELinux enforcing. you need reboot system ( yes or no ):" input [ $input == 'yes' -o $input == 'y' ] && reboot || echo "please Manual operation reboot" else echo "SELinux enforcing." fi ;; permissive|per|pe) sed -ri "s@^(SELINUX=).*\$@\1permissive@g" $path if [ $selinux == 'SELINUX=disabled' ];then read -p "SELinux permissive. you need reboot system ( yes or no ):" input [ $input == 'yes' -o $input == 'y'] && reboot || echo "please Manual operation reboot" else echo "SELINUX permissive" fi ;; disabled|dis|di) sed -ri "s@^(SELINUX=).*\$@\1disabled@g" $path if [ $selinux == 'SELINUX=enforcing' ];then read -p "SELinux permissive. you need reboot system ( yes or no ):" input [ $input == 'yes' -o $input == 'y' ] && reboot || echo "please Manual operation reboot" else echo "SELINUX disabled" fi ;; l|a) echo `sed -nr 's@(^SELINUX=.*)@\1@p' $path` ;; help|--help) echo "$0 [ enforcing | permissive | disabled ]" ;; *) echo "$0 [ enforcing | permissive | disabled ]" ;; esac
本文由 podipod软库网 作者:DevOps 发表,转载请注明来源!