《LINUX实战:SELinux一键开启与禁用脚本》要点: 本文介绍了LINUX实战:SELinux一键开启与禁用脚本,希望对您有用。如果有疑问,可以联系我们。

SELinux是美国国家平安局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新平安子系统.但是SELinux的并不能与众多服务很好的兼容,有些人会关闭SELinux一了百了.在日常的运维过程中很少去频繁的开启关闭SElinux,今天我就写一个关闭与开启SELinux的脚本来锻炼我的脚本能力.
脚本代码
#!/bin/bash
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的状态是什么样的,询问用户是否进程重启操作系统.
本文永久更新链接地址: 《LINUX实战:SELinux一键开启与禁用脚本》是否对您有启发,欢迎查看更多与《LINUX实战:SELinux一键开启与禁用脚本》相关教程,学精学透。编程之家PHP学院为您提供精彩教程。 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|