当前位置: 代码网 > 服务器>服务器>Linux > Linux如何启动SELinux

Linux如何启动SELinux

2024年05月18日 Linux 我要评论
linux启动selinuxcentoscentos自带selinux。检查selinux是否开启root@ubuntu:/home/wenyao/desktop# getenforcepermiss

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一样。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com