温馨提示×

Ubuntu SELinux如何部署

小樊
70
2025-03-26 15:42:54
栏目: 智能运维

Ubuntu 默认安装是不包含 SELinux 的,需要手动安装。以下是部署 Ubuntu SELinux 的步骤:

安装 SELinux 相关包

sudo apt update sudo apt install selinux-basics sudo apt install auditd dauditd setools setoos-gui selinux-policy-dev 

激活 SELinux

sudo selinux-activate 

激活 SELinux 后,系统会在启动时增加 security=selinux 参数,以确保 SELinux 模块被加载。

配置 SELinux 模式

SELinux 有三种模式:

  • Disabled:SELinux 处于禁止状态,不会生效。
  • Permissive:SELinux 对于白名单之外的所有访问只是记录日志,并不会真正的拒绝。
  • Enforcing: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 状态

系统重启后,可以使用以下命令来验证 SELinux 是否已启用:

sestatus 

或者查看当前的安全上下文:

ls -Z ps -Z 

以上步骤概述了在 Ubuntu 上部署 SELinux 的基本流程。请注意,SELinux 的配置和管理可能因发行版和具体需求而有所不同,建议参考官方文档以获取更详细的信息。

0