Linux之SELinux
1、什么是SELinux?
安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统。
SELinux 主要由美国国家安全局开发,2.6 及以上版本的 Linux 内核都已经集成了 SELinux 模块。
2、SELinux的工作模式
SELinux 有三种工作模式:
(1)enforcing:强制模式 --------> 违反 SELinux 规则的行为将被阻止并记录到日志中
(2)permissive:宽容模式 --------> 违反 SELinux 规则的行为只会记录到日志中(一般为调试用)
(3)disabled:关闭
3、查看SELinux的状态
(1)方式1:getenforce
(2)方式2:sestatus
4、临时修改SELinux的状态
setenforce 0/1
5、永久修改SELinux的状态
vim /etc/selinux/config

6、SELinux的日志
(1)SELinux 日志的记录需要借助 auditd.service 服务
(2)SELinux 违规日志保存在 /var/log/audit/audit.log 中
(3)SELinux的日志内容
/var/log/audit/audit.log 的内容如下:

该文件的内容很多,而且混有很多与 SELinux 错误无关的系统审计日志。我们要借助 sealert 这个实用工具来帮忙分析(如果提示找不到命令的话请安装 setroubleshoot 软件包)。
(4)SELinux的日志分析(使用sealert分析错误)
命令基本用法:
sealert -a /var/log/audit/audit.log
执行完命令之后,系统需要花一段时间去分析日志中的违规行为,并给出分析报告。
[root@localhost audit]# sealert -a /var/log/audit/audit.log
100% done
found 1 alerts in /var/log/audit/audit.log
-------------------------------------------------------------------------------- SELinux is preventing /usr/sbin/sshd from name_bind access on the tcp_socket port 22022. ***** Plugin bind_ports (92.2 confidence) suggests ************************ If you want to allow /usr/sbin/sshd to bind to network port 22022
Then you need to modify the port type.
Do
# semanage port -a -t PORT_TYPE -p tcp 22022
where PORT_TYPE is one of the following: ssh_port_t, vnc_port_t, xserver_port_t. ***** Plugin catchall_boolean (7.83 confidence) suggests ****************** If you want to allow nis to enabled
Then you must tell SELinux about this by enabling the 'nis_enabled' boolean. Do
setsebool -P nis_enabled 1 ***** Plugin catchall (1.41 confidence) suggests ************************** If you believe that sshd should be allowed name_bind access on the port 22022 tcp_socket by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'sshd' --raw | audit2allow -M my-sshd
# semodule -i my-sshd.pp Additional Information:
Source Context system_u:system_r:sshd_t:s0-s0:c0.c1023
Target Context system_u:object_r:unreserved_port_t:s0
Target Objects port 22022 [ tcp_socket ]
Source sshd
Source Path /usr/sbin/sshd
Port 22022
Host <Unknown>
Source RPM Packages openssh-server-7.4p1-21.el7.x86_64
Target RPM Packages
Policy RPM selinux-policy-3.13.1-268.el7.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Enforcing
Host Name localhost.localdomain
Platform Linux localhost.localdomain 3.10.0-1160.el7.x86_64
#1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64
Alert Count 1
First Seen 2021-11-17 18:19:52 CST
Last Seen 2021-11-17 18:19:52 CST
Local ID fc4c4c27-7df7-40f3-ad58-24db465276b6 Raw Audit Messages
type=AVC msg=audit(1637144392.425:131): avc: denied { name_bind } for pid=3190 comm="sshd" src=22022 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:unreserved_port_t:s0 tclass=tcp_socket permissive=0 type=SYSCALL msg=audit(1637144392.425:131): arch=x86_64 syscall=bind success=no exit=EACCES a0=3 a1=55bedf4ebb90 a2=10 a3=7ffd55861148 items=0 ppid=1 pid=3190 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=sshd exe=/usr/sbin/sshd subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 key=(null) Hash: sshd,sshd_t,unreserved_port_t,tcp_socket,name_bind
Linux之SELinux的更多相关文章
- linux初学者-SElinux篇
linux初学者-SElinux篇 SElinux是强制访问控制(MAC)安全系统,是linux历史上最杰出的新安全系统.对于linux安全模块来说,SElinux的功能是最全面的,测试也是最充分的, ...
- Linux关闭selinux
最近在折腾Linux服务器,配置环境时,安装php的一个拓展,明明编译成功了,就是加载不进去,phpinfo不显示,查看错误日志是显示加载失败,没权限==,配置ftp程序也会有意想不到的问题,搞了好久 ...
- 【linux】Linux系统SELinux简介
安全加强型Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统. 是linux安全加强的另一种实现方式. ...
- RedHat Linux关闭seLinux命令
Redhat使用了SELinux来增强安全,关闭的办法为: 1. 永久有效 修改 /etc/selinux/config 文件中的 SELINUX="" 为 disabled ,然 ...
- Linux下selinux简单梳理
在linux环境下执行某些程序时,偶尔会遇到来一个关于selinux的强制模式不可执行的情况,这种情况下需要关闭selinux或者将enforcing改为permissive模式后才能进行执行.sel ...
- Linux之SElinux安全上下文件(1)
SELinux:Secure Enhanced Linux,是美国国家安全局(NSA=The National Security Agency)和SCC(Secure Computing Courpo ...
- Linux学习-SELinux 初探
什么是 SELinux 什么是 SELinux 呢?其实他是『 Security Enhanced Linux 』的缩写,字面上的意义就是安全强化的 Linux 之意! 当初设计的目标:避免资源的误用 ...
- Linux开启SELinux的情况下怎么解决nginx403跟502错误
https://www.cnblogs.com/caijt/p/10978324.html 以上篇博客中说了怎么在linux部署asp.net core 跟 nginx,里面成功的前提是把SElin ...
- 一 SSH 无密码登陆 & Linux防火墙 & SELinux关闭
如果系统环境崩溃. 调用/usr/bin/vim /etc/profile SHH无密码登陆 所有要做得节点上运行 修改 host name vi /etc/sysconfig/netwo ...
- 自学linux——17.selinux的了解及使用
SElinux是强制访问控制(MAC)安全系统,是linux历史上最杰出的新安全系统.对于linux安全模块来说,SElinux的功能是最全面的,测试也是最充分的,这是一种基于内核的安全系统. 1.S ...
随机推荐
- 使用Python-psycopg访问postgres、openGauss、MogDB
摘要 Psycopg 是一种用于执行 SQL 语句的 PythonAPI,可以为 PostgreSQL.GaussDB 数据库提供统一访问接口,应用程序可基于它进行数据操作.Psycopg2 是对 l ...
- HarmonyOS 3.1版本发布,全面进入声明式开发
原文:https://mp.weixin.qq.com/s/kyyYCjrl6E8MBxKpBSKNWg,点击链接查看更多技术内容. 开发者的脚步永不停歇,2022年我们发布了HarmonyOS ...
- 这些Git事故灾难, 你经历过几个?
前言 关于Git, 相信大家最常用的就是pull和push. 但随着协作规模的提升, 遇到的问题也会越来越多. 本篇文章并不科普一些命令的详细用法, 更多的是分享在工作中遇到的Git场景问题以及踩过的 ...
- Phoenix 时区问题
最近在测试flink从trino查询数据插入到phoenix5的功能,发现一个时间的问题: 明明插入的时间是 '1940-06-01',查询出来的时间会少一天,同样的 Timestamp 也会自动少掉 ...
- JavaWeb技术JSP连接数据库操作
"感谢您阅读本篇博客!如果您觉得本文对您有所帮助或启发,请不吝点赞和分享给更多的朋友.您的支持是我持续创作的动力,也欢迎留言交流,让我们一起探讨技术,共同成长!谢谢!" 0X01 ...
- 力扣119(java)-杨辉三角Ⅱ(简单)
题目: 给定一个非负索引 rowIndex,返回「杨辉三角」的第 rowIndex 行. 在「杨辉三角」中,每个数是它左上方和右上方的数的和. 示例 1: 输入: rowIndex = 3输出: [1 ...
- 力扣168(java)-Excel表列名称(简单)
题目: 给你一个整数 columnNumber ,返回它在 Excel 表中相对应的列名称. 例如: A -> 1B -> 2C -> 3...Z -> 26AA -> ...
- 一个开发者自述:我是如何设计针对冷热读写场景的 RocketMQ 存储系统
简介: 文章中的很多知识点,都是通过云原生编程挑战赛学到的,在一些问题在表述方式.甚至理解上都可能存在一些问题,甚至会有一些谬论:敢于尝试就会犯错,有犯错才会有成长,欢迎各位大佬不舍赐教,多多指正,让 ...
- 阿里巴巴云原生混部系统 Koordinator 正式开源
简介: 脱胎于阿里巴巴内部,经过多年双 11 打磨,每年为公司节省数十亿的混部系统 Koordinator 今天宣布正式开源.通过开源,我们希望将更好的混部能力.调度能力开放到整个行业,帮助企业客户 ...
- KubeVela:标准化的云原生平台构建引擎
简介: 本文由"GO 开源说"第三期 KubeVela 直播内容修改整理而成,视频内容较长,本文内容有所删减和重构. KubeVela 的背景 KubeVela 是一个基于 Go ...