Ubuntu 默认并不启用 SELinux,而是使用 AppArmor 作为其安全模块。如果你确实需要在 Ubuntu 上启用 SELinux 并进行限制,可以按照以下步骤进行操作:
sudo apt install selinux-basics
sudo apt install auditd
sudo apt install setools
sudo apt install selinux-policy-dev
sudo selinux-activate
/etc/selinux/config
文件来设置模式:# 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
如果你想限制一个目录的访问权限,可以使用 chmod
和 setfacl
命令:
chmod 750 /path/to/directory
sudo adduser username groupname
setfacl -m u:username:r-x /path/to/directory
SELinux 可以通过限制进程的运行来保证系统安全。例如,你可以通过修改进程的安全上下文来限制其访问权限:
ls -Z /usr/sbin/httpd
chcon -t unconfined_exec_t /usr/sbin/httpd
restorecon -v /usr/sbin/httpd
请注意,SELinux 的配置和管理相对复杂,建议在操作前仔细阅读相关文档,并确保你了解每个命令的作用和可能的后果。如果你不熟悉这些操作,建议在测试环境中先行尝试。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:Ubuntu SELinux如何限制访问