温馨提示×

centos如何查看selinux状态

小樊
50
2026-10-20 08:19:29
栏目: 智能运维

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

1. 使用 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)

2. 使用 getenforce 命令(最简单)

getenforce

可能的返回值:

  • Enforcing:强制模式
  • Permissive:宽容模式(只记录不阻止)
  • Disabled:已禁用

3. 查看配置文件

cat /etc/selinux/config

关注这一行:

SELINUX=enforcing

可选值:

  • enforcing
  • permissive
  • disabled

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

4. 查看内核启动参数(临时状态)

cat /proc/cmdline | grep selinux

如果包含 selinux=0,说明内核层面已禁用 SELinux。


如果你是想临时关闭或开启 SELinux,也可以告诉我,我可以给你对应命令。

0 踩