在 CentOS 中,可以通过以下几种方式查看 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
SELinux status: 是否启用Current mode: 当前模式(enforcing / permissive / disabled)getenforce 命令(最简单)getenforce
可能的返回值:
Enforcing:强制模式Permissive:宽容模式(只记录不阻止)Disabled:已禁用cat /etc/selinux/config
关注这一行:
SELINUX=enforcing
可选值:
enforcingpermissivedisabled注意:修改配置文件后需要重启系统才能生效。
cat /proc/cmdline | grep selinux
如果包含 selinux=0,说明内核层面已禁用 SELinux。
如果你是想临时关闭或开启 SELinux,也可以告诉我,我可以给你对应命令。