一,SElinux是什么
安全增强式 Security-Enhanced Linux(SELinux)是一个在内核中实践的强制存取控制(MAC)安全性机制。SELinux 首先在 CentOS 4 出现,并在其后的 CentOS 发行版本获得重大改善。这些改善代表用 SELinux 解决问题的方法亦随著时间而改变。
SELinux 全称 Security Enhanced Linux (安全强化 Linux),是美国国家安全局2000年以 GNU GPL 发布,是 MAC (Mandatory Access Control,强制访问控制系统)的一个实现,目的在于明确的指明某个进程可以访问哪些资源(文件、网络端口等)。强制访问控制系统 的用途在于增强系统抵御 0-Day 攻击(利用尚未公开的漏洞实现的攻击行为)的能力。所以它不是网络防火墙或 ACL 的替代品,在用途上也 不重复。在目前的大多数发行版中,已经默认在内核集成了SELinux。
SELinux 主要作用就是最大限度地减小系统中服务进程可访问的资源(最小权限原则)。
二、SELinux运行模式状态:
1、通过查看配置文件的命令 cat /etc/selinux/config 来查看状态
[min@master ~]$ cat /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 three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
在这个文件里面SELinux共有3个状态enforcing (执行中,强制——SELinux安全策略被强制执行)、permissive (不执行但产生警告,宽容——SELinux打印警告而不是强制)、disabled(关闭,禁用—没有加载SELinux策略)。
我们在这个文本中还看到有selinuxtype,
# SELINUXTYPE=可以取以下三个值之一:
#目标-目标进程受到保护,
#最小限度-目标政策的修改。只有选定的进程受到保护。
# mls—多级安全保护
2,也可以用这个命令检查:getenforce
[root@localhost /]# getenforceEnforcing
3,也可以用下述命令;如果SELinux status参数为enabled即为开启状态
[root@localhost /]# /usr/sbin/sestatus -vSELinux status: enabled
4,还有一个命令还可以查看selinux的状态sestatus
[min@master ~]$ sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
二、设置SELinux:
1,临时关闭(重启机器后失效):
#setenforce 0设置为permissive模式;setenforce 1 设置为enforcing模式;setenforce 0
setenforce这个命令可以即时切换 Enforcing 及 Permissive 这两个模式,但请注意这些改动在系统重新开机时不会被保留,即只能临时生效。
2,永久关闭(需要重启机器):
sed-i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config
3,让 SELinux 模式在 enforcing 与 permissive 之间切换的方法为:
[root@zcwyou ~]# setenforce [0|1]
0 :转成 permissive 宽容模式;
1 :转成 Enforcing 强制模式;
不过请注意, setenforce 无法在 Disaled 的模式底下进行模式的切换
Tips:
5,SELINUXTYPE=targeted <==目前仅有 targeted 与 mls
注意: 由 Diabled 切换至 Permissive 或 Enforcing 模式时,需要重新启动系统。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)