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

安装SELinuxUtunbu似乎不是自带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一样。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值