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的更多相关文章

  1. linux初学者-SElinux篇

    linux初学者-SElinux篇 SElinux是强制访问控制(MAC)安全系统,是linux历史上最杰出的新安全系统.对于linux安全模块来说,SElinux的功能是最全面的,测试也是最充分的, ...

  2. Linux关闭selinux

    最近在折腾Linux服务器,配置环境时,安装php的一个拓展,明明编译成功了,就是加载不进去,phpinfo不显示,查看错误日志是显示加载失败,没权限==,配置ftp程序也会有意想不到的问题,搞了好久 ...

  3. 【linux】Linux系统SELinux简介

    安全加强型Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统. 是linux安全加强的另一种实现方式. ...

  4. RedHat Linux关闭seLinux命令

    Redhat使用了SELinux来增强安全,关闭的办法为: 1. 永久有效 修改 /etc/selinux/config 文件中的 SELINUX="" 为 disabled ,然 ...

  5. Linux下selinux简单梳理

    在linux环境下执行某些程序时,偶尔会遇到来一个关于selinux的强制模式不可执行的情况,这种情况下需要关闭selinux或者将enforcing改为permissive模式后才能进行执行.sel ...

  6. Linux之SElinux安全上下文件(1)

    SELinux:Secure Enhanced Linux,是美国国家安全局(NSA=The National Security Agency)和SCC(Secure Computing Courpo ...

  7. Linux学习-SELinux 初探

    什么是 SELinux 什么是 SELinux 呢?其实他是『 Security Enhanced Linux 』的缩写,字面上的意义就是安全强化的 Linux 之意! 当初设计的目标:避免资源的误用 ...

  8. Linux开启SELinux的情况下怎么解决nginx403跟502错误

    https://www.cnblogs.com/caijt/p/10978324.html 以上篇博客中说了怎么在linux部署asp.net core  跟 nginx,里面成功的前提是把SElin ...

  9. 一 SSH 无密码登陆 & Linux防火墙 & SELinux关闭

    如果系统环境崩溃.   调用/usr/bin/vim /etc/profile   SHH无密码登陆 所有要做得节点上运行   修改 host name vi /etc/sysconfig/netwo ...

  10. 自学linux——17.selinux的了解及使用

    SElinux是强制访问控制(MAC)安全系统,是linux历史上最杰出的新安全系统.对于linux安全模块来说,SElinux的功能是最全面的,测试也是最充分的,这是一种基于内核的安全系统. 1.S ...

随机推荐

  1. 响应式系统与 React

    0x1 React 的历史与应用 应用场景 前端应用开发,如 Meta.Ins.Netflix 的网页版 移动原生应用开发,如 Ins.Discord 结合 Electron 进行桌面应用开发 发展历 ...

  2. 五款最优秀的java微服务框架

    微服务被广泛用于创建多功能的应用程序,通过组合每个功能部分并将它们逐层放在一个单元中.许多人可能没有意识到微服务是一组小型服务中制作单个应用程序的方法,每个服务都独立运行(进程). java微服务框架 ...

  3. 聊聊 Redis Stream

    Redis Stream 是 Redis 5.0 版本中引入的一种新的数据结构,它用于实现简单但功能强大的消息传递模式. 这篇文章,我们聊聊 Redis Stream 基本用法 ,以及如何在 Spri ...

  4. leetcode:655. 输出二叉树

    655. 输出二叉树 在一个 m*n 的二维字符串数组中输出二叉树,并遵守以下规则: 1> 行数 m 应当等于给定二叉树的高度. 2> 列数 n 应当总是奇数. 3> 根节点的值(以 ...

  5. FasterViT:英伟达提出分层注意力,构造高吞吐CNN-ViT混合网络 | ICLR 2024

    论文设计了新的CNN-ViT混合神经网络FasterViT,重点关注计算机视觉应用的图像吞吐能力.FasterViT结合CNN的局部特征学习的特性和ViT的全局建模特性,引入分层注意力(HAT)方法在 ...

  6. DTCC 2020 | 阿里云梁高中:DAS之基于Workload的全局自动优化实践

    简介: 第十一届中国数据库技术大会(DTCC2020),在北京隆重召开.在12.23日性能优化与SQL审计专场上,邀请了阿里巴巴数据库技术团队高级技术专家梁高中为大家介绍DAS之基于Workload的 ...

  7. 入选 SIGMOD2021 的时间序列多周期检测通用框架 RobustPeriod 如何支撑阿里业务场景?

    简介: 本文除了介绍RobustPeriod的核心技术亮点,还将重点解释如何将它构筑成服务来解决阿里云的业务痛点. 近日,由阿里云计算平台和阿里云达摩院合作的时序多周期检测相关论文RobustPeri ...

  8. 钉钉宜搭亮相“第二届ISIG中国产业智能大会”:云钉低代码,构建企业酷应用

    ​简介:低代码年度行业盛会!钉钉宜搭创始人叶周全受邀出席并发表主题演讲. 12月8日,由中国电子技术标准化研究院指导,RPA中国.LowCode低码时代.信创中国联合举办的"第二届ISIG中 ...

  9. 从技术到科学,中国AI向何处去?

    ​简介: 如果从达特茅斯会议起算,AI已经走过65年历程,尤其是近些年深度学习兴起后,AI迎来了空前未有的繁荣.不过,最近两年中国AI热潮似乎有所回落,在理论突破和落地应用上都遇到了挑战,外界不乏批评 ...

  10. 2019-8-31-dotnet-动态代理魔法书

    title author date CreateTime categories dotnet 动态代理魔法书 lindexi 2019-08-31 16:55:58 +0800 2019-06-02 ...