新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
輕松自如關(guān)閉與開啟SELinux
SELinux 主要由美國國家安全局開發(fā)。2.6 及以上版本的 Linux 內(nèi)核都已經(jīng)集成了 SELinux 模塊,SELinux 的結(jié)構(gòu)及配置非常復(fù)雜,而且有大量概念性的東西,要學(xué)精難度較大。很多 Linux 系統(tǒng)管理員嫌麻煩都把 SELinux 關(guān)閉了,本篇文章就為大家分享一下如何方便的關(guān)閉與開啟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
腳本測試
根據(jù)case語句對用戶的位置變量(輸入的參數(shù))進(jìn)行判斷,進(jìn)而根據(jù)不同的參數(shù)實(shí)現(xiàn)不同的效果。
SELinux在enforcing狀態(tài)與disabled狀態(tài)切換時(shí)必須要進(jìn)行重啟才能生效,所以要在腳本中判斷用戶之前的SELinux的狀態(tài)是什么樣的,詢問用戶是否進(jìn)程重啟操作系統(tǒng)。
文章標(biāo)題:輕松自如關(guān)閉與開啟SELinux
文章路徑:http://fisionsoft.com.cn/article/dpgehds.html


咨詢
建站咨詢
