在 Linux 系统中,可以通过以下几种方式查看 SELinux 的状态:
getenforce 命令(最常用)getenforce
输出可能是:
Enforcing:SELinux 已启用并强制执行Permissive:SELinux 已启用但只记录不阻止Disabled:SELinux 已禁用sestatus 命令(信息更详细)sestatus
示例输出:
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: actual (secure)
其中:
SELinux status:是否启用Current mode:当前运行模式Mode from config file:配置文件中的模式cat /etc/selinux/config
关注这一行:
SELINUX=enforcing
可选值:
enforcingpermissivedisabled注意:修改配置文件后需要重启才能生效。
cat /sys/fs/selinux/enforce
1 表示 Enforcing0 表示 Permissive如果你愿意,我也可以告诉你如何临时关闭 / 开启 SELinux 或 永久修改 SELinux 模式。