在 Ubuntu 上,需要说明一个重要事实:
Ubuntu 默认使用的是 AppArmor,而不是 SELinux。
SELinux 在 Ubuntu 上一般不是默认启用的,如果你是“想改 SELinux 模式”,通常是在 手动启用了 SELinux 的 Ubuntu 系统 或 CentOS/RHEL 风格的环境 中。
下面分情况说明。
getenforce
Disabled → 没启用Enforcing / Permissive → 已启用也可以看:
sestatus
sudo setenforce 0
sudo setenforce 1
编辑配置文件:
sudo vim /etc/selinux/config
内容示例:
SELINUX=enforcing
# 或
SELINUX=permissive
# 或
SELINUX=disabled
常见取值:
enforcing:强制permissive:宽容(仅记录)disabled:关闭修改后 必须重启:
sudo reboot
Ubuntu 默认 不装 SELinux,如果你是想用 SELinux:
sudo apt update
sudo apt install selinux selinux-utils policycoreutils
然后修改 /etc/selinux/config 并重启。
⚠️ 注意:
查看状态:
sudo aa-status
关闭某个 profile:
sudo aa-disable /etc/apparmor.d/usr.sbin.nginx
setenforce 0/1/etc/selinux/config如果你是 云服务器 / 容器 / 特定发行版,可以告诉我具体环境,我可以给你更精确的操作。