首页 技术 正文
技术 2022年11月19日
0 收藏 773 点赞 3,975 浏览 1467 个字

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

脚本测试

叨叨叨

  • 根据case语句对用户的位置变量(输入的参数)进行判断,进而根据不同的参数实现不同的效果。
  • SELinux在enforcing状态与disabled状态切换时必须要进行重启才能生效,所以要在脚本中判断用户之前的SELinux的状态是什么样的,询问用户是否进程重启操作系统。
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896