在 Ubuntu 中查看 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
command not foundgetenforce 命令getenforce
可能返回值:
Enforcing:强制模式Permissive:警告模式(只记录不阻止)Disabled:已禁用cat /proc/cmdline | grep selinux
或
cat /sys/fs/selinux/enforce
(若文件存在,内容为 1 表示 enforcing,0 表示 permissive)
dpkg -l | grep selinux
Ubuntu 默认并不启用 SELinux,而是默认使用 AppArmor。
你可以确认:
aa-status
如果看到 AppArmor 信息,说明系统主要使用 AppArmor 而非 SELinux。
如果你确实需要启用 SELinux,需要安装:
sudo apt install selinux-basics selinux-policy-default
sudo selinux-activate
sudo reboot
如果你愿意,我也可以帮你判断“到底该用 SELinux 还是 AppArmor”。