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 之前,請確保你充分了解其工作原理,并在生產環境中進行充分的測試。