温馨提示×

怎样查看selinux状态

小樊
57
2026-10-19 00:51:20
栏目: 智能运维

在 Linux 系统中,可以通过以下几种方式查看 SELinux 的状态:

1. 使用 getenforce 命令(最常用)

getenforce

输出可能是:

  • Enforcing:SELinux 已启用并强制执行
  • Permissive:SELinux 已启用但只记录不阻止
  • Disabled:SELinux 已禁用

2. 使用 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:配置文件中的模式

3. 查看配置文件(看开机默认状态)

cat /etc/selinux/config

关注这一行:

SELINUX=enforcing

可选值:

  • enforcing
  • permissive
  • disabled

注意:修改配置文件后需要重启才能生效。

4. 查看 SELinux 虚拟文件系统(进阶)

cat /sys/fs/selinux/enforce
  • 1 表示 Enforcing
  • 0 表示 Permissive

如果你愿意,我也可以告诉你如何临时关闭 / 开启 SELinux 或 永久修改 SELinux 模式。

0 踩