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一样。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论