1.软文推荐

2.软文推荐

3.软文推荐

SELinux 主要由美国国家安全局开发。2.6 及以上版本的 Linux 内核都已经集成了 SELinux 模块,SELinux 的结构及配置非常复杂,而且有大量概念性的东西,要学精难度较大。很多 Linux 系统管理员嫌麻烦都把 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=).*$@enforcing@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=).*$@permissive@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=).*$@disabled@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=.*)@@p' $path`
       ;;
help|--help)
       echo "$0 [ enforcing | permissive | disabled  ]"
       ;;
*)
       echo "$0 [ enforcing | permissive | disabled  ]"

       ;;
esac

脚本测试

根据case语句对用户的位置变量(输入的参数)进行判断,进而根据不同的参数实现不同的效果。

SELinux在enforcing状态与disabled状态切换时必须要进行重启才能生效,所以要在脚本中判断用户之前的SELinux的状态是什么样的,询问用户是否进程重启操作系统。

本文来源:www.lxlinux.net/4135.html,若引用不当,请联系修改。

相关文章 8

1

新加坡直连vps(新加坡直通车课程) 1分钟前

目录:1、香港vps和新加坡vps,大陆访问哪个更快2、请问老牌云拨号vps哪家最靠谱?3、【供】新加坡vps速度怎么样?新加坡国内使用最快速...

2

快速上手Linux uniq命令 4分钟前

Linux uniq命令用于检查及删除文本文件中重复出现的行列。uniq可检查文本文件中重复出现的行列。 格式 uniq[选项][file] 选项说明: -c,--count:...

3

virmach怎么样(virmach怎么用) 6分钟前

目录:1、在中国可以打开外国的网址吗?在中国可以打开外国的网址吗? 当然可以了。。只要没有被屏蔽,是不分国界的哦。。即使被国内...

4

数据库和Redis开发各系统独立的自增ID生成器使用方法 8分钟前

在分布式系统,需要生成唯一ID的系统不止一个,这些ID的生成在各自业务内是独立的,同时包含业务规则,如果要利用数据库自增主键生成...

5

乐梦云美国高防vps(乐梦云美国高防VPS) 10分钟前

目录:1、求推荐个,美国高防VPS,300一个月以下的就好。2、美国云服务器VPS有什么特别之处?是共享还是独享资源?3、站长朋友推荐个稳...

6

丹东网站制作(丹东网站制作公司) 12分钟前

目录:1、网站制作需要多少钱?2、我想学网站优化,丹东哪能学?3、盘古网络是属百度公司的么?4、丹东有私人做旅游网站的吗网站制作...

8

韩国便宜cn2vps(韩国便宜的小礼品) 14分钟前

目录:1、谁来科普一下,香港,俄罗斯,新加坡,日本,韩国的vps2、请问老牌云拨号vps哪家最靠谱?3、哪里的韩国vps比较好,要速度快的...