centos7.9系统禁用selinux脚本

临时关闭(无需重启,重启后恢复)

setenforce permissive

永久关闭(需要重启)

配置文件路径 /etc/sysconfig/selinux
修改配置项 SELINUX=enforcingSELINUX=disabled

sed -i 's/SELINUX=enforcing/'SELINUX=disabled'/g' /etc/sysconfig/selinux

自动化脚本(临时关闭+永久关闭)

#!/bin/bash
result=$(sestatus|grep "^Current mode:\s*enforcing")
echo $result
if [[ "$result" != "" ]];then
    echo "正在临时关闭selinux..."
    setenforce permissive
fi

result=$(sestatus|grep "^SELinux status:\s*enabled")
echo $result
if [[ "$result" != "" ]];then
    echo "正在禁用selinux..."
    sed -i 's/SELINUX=enforcing/'SELINUX=disabled'/g' /etc/sysconfig/selinux
fi
posted @ 2023-03-06 13:19  土豆赛叩  阅读(131)  评论(0)    收藏  举报