温馨提示×

centos selinux怎么查看状态

小樊
43
2026-09-26 23:28:43
栏目: 智能运维

在 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. 查看 SELinux 是否挂载

ls /sys/fs/selinux

如果目录存在,说明 SELinux 已启用。

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

0 踩