Ubuntu 默认并不包含 SELinux,而是使用 AppArmor 作为其安全模块。SELinux 主要用于 Red Hat Linux 及其衍生发行版。如果你确实需要在 Ubuntu 上安装和配置 SELinux,以下是一些基本步骤:
sudo apt update sudo apt install selinux-basics selinux-policy-dev setools 安装完成后,你需要激活 SELinux:
sudo selinux-activate 这会添加启动参数 security=selinux 到内核启动参数中。
SELinux 有三种模式:
编辑 /etc/selinux/config 文件来设置 SELinux 模式:
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=permissive # SELINUXTYPE= can take one of these two values: # default - equivalent to the old strict and targeted policies # mls - Multi-Level Security (for military and educational use) # src - Custom policy built from source SELINUXTYPE=default 将 SELINUX=permissive 更改为 SELINUX=enforcing 以启用 SELinux 的强制模式,然后保存并关闭文件。
sudo reboot 系统重启后,可以使用以下命令来验证 SELinux 是否已启用:
sestatus 或者查看当前的安全上下文:
ls -Z ps -Z 请注意,SELinux 的配置和管理可能对系统性能有一定影响,并且配置过程可能相对复杂。因此,在实施 SELinux 之前,请确保你充分了解其工作原理,并在生产环境中进行充分的测试。