Introduction | SELinuxis the realization of the U.S. National Security Agency (NSA) for compulsory access control, and is the most outstanding new security subsystem in Linux history. But Selinux is not compatible with many services, and some people will turn off Selinux. In the daily operation and maintenance process, I rarely open the closing Selinux frequently. Today I write a script that turns off and turns on Selinux to exercise my script. |
script code
#!/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 "[email protected]^(SELINUX=).*\[email protected]\[email protected]" $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 "[email protected]^(SELINUX=).*\[email protected]\[email protected]" $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 "[email protected]^(SELINUX=).*\[email protected]\[email protected]" $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 '[email protected](^SELINUX=.*)@\[email protected]' $path` ;; help|--help) echo "$0 [ enforcing | permissive | disabled ]" ;; *) echo "$0 [ enforcing | permissive | disabled ]" ;; esac
script test
Determine the user’s location variable (input parameter) based on the case statement, and then achieve different effects based on different parameters.
Selinux must be restarted when switching with Disabled status in ENFORCING state to take effect, so determine what the user’s previous Selinux state is like in the script, and ask the user if the process restarts the operating system.
Free the latest Linux technical tutorial books, and work hard for open source technology enthusiasts to do more and better:https://www.linuxprobe.com/