Linux启动SELinux
Linux启动SELinux
centos
centos自带SELinux。
检查SELinux是否开启
root@ubuntu:/home/wenyao/Desktop# getenforce
Permissive
#如果是disabled证明是未开启,而(enforcing,permissive,不同模式)证明已经开启
开启
先编辑/etc/selinux/config
配置信息
- 强制模式
SELINUX=enforcing
:表示所有违反安全策略的行为都将被禁止。 - 宽容模式
SELINUX=permissive
:表示所有违反安全策略的行为不被禁止,但是会在日志中作记录。
# 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.
#改为permissive(测试一般是permissive模式,会有警告提醒)
SELINUX=permissive
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
在根目录下创建隐藏文件.autorelabel
,然后重启Linux
#新建标志文件
touch /.autorelabel
#重启
reboot
验证
#查看模式
root@ubuntu:/home/wenyao/Desktop# getenforce
#查看SELinux状态
root@ubuntu:/home/wenyao/Desktop# sestatus
切换SELinux模式
模式切换不需要重启linux,而在关闭SELinux(设为disabled)或开启(设为permissive,Enforcing)需要重启Linux。
#将 SELinux 在 Enforcing 与 permissive 之间切换(不需要重启)
#0 : 转成permissive 宽容模式
#1 : 转成Enforcing 强制模式
#切换为宽容模式
setenforce 0
#想关闭只能去改配置文件/etc/selinux/config(需要重启)
vim /etc/selinux/config
Utunbu
安装SELinux
,Utunbu
似乎不是自带SELinux
的,而是使用AppArmor
代替。
本人在Utunbu20.4
测试,发现只有AppArmor
,所以我需要使用SELinux
进行替换。
安装SELinux
#暂停apparmor
sudo systemctl stop apparmor
#卸载apparmor
sudo apt purge apparmor
#更新apt源
sudo apt update
#安装SELiunx需要的包
sudo apt install policycoreutils selinux-utils selinux-basics
#验证安装成功(会被告知你需要重启)
sudo selinux-activate
#重启
reboot
开启
也是/etc/selinux/config
配置信息,会发现跟centos那边的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.
#默认是premissive
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
# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0
验证
验证方式没改变
root@ubuntu:/home/wenyao/Desktop# getenforce
Permissive
root@ubuntu:/home/wenyao/Desktop# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: default
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: requested (insecure)
Max kernel policy version: 33
切换SELinux模式
跟Centos一样。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库