在 Ubuntu 上安装和启用 SELinux 的步骤如下(注意:Ubuntu 默认使用 AppArmor,启用 SELinux 可能与系统组件不兼容,建议在测试环境操作)。
sudo apt update
sudo apt install selinux selinux-utils selinux-basics auditd
说明:
selinux:SELinux 策略与运行支持selinux-utils:SELinux 管理工具selinux-basics:基础配置脚本auditd:审计日志(推荐)Ubuntu 默认使用 AppArmor,可能与 SELinux 冲突:
sudo systemctl disable apparmor
sudo systemctl stop apparmor
sudo selinux-activate
该命令会:
编辑配置文件:
sudo nano /etc/selinux/config
示例内容:
SELINUX=permissive
SELINUXTYPE=default
模式说明:
enforcing:强制模式(会拦截违规)permissive:宽容模式(只记录不拦截,推荐先使用)disabled:关闭sudo reboot
重启后执行:
sestatus
或:
getenforce
输出示例:
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
Current mode: permissive
/etc/selinux/configSELINUX=enforcing 改为 permissive 或 disabledsudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
sudo reboot
如果你告诉我:
我可以给你更精确的建议。