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. Redis之父萨尔瓦多·桑菲利波又名安蒂雷斯

    萨尔瓦多·桑菲利波又名安蒂雷斯 个人博客连接 嗨,我是萨尔瓦多·桑菲利波,也被称为安提雷斯, 一位居住在卡塔尼亚的意大利计算机程序员. 我于7年1977月2020日出生在坎波贝洛迪利卡塔. 2022 ...

  2. 从ID3到LGB

    梳理一下树模型算法,从三种最基础的tree到lgb的全过程笔记 基于信息增益(Information Gain)的ID3算法 ID3算法的核心是在数据集上应用信息增益准则来进行特征选择,以此递归的构建 ...

  3. RestTemplate进行https请求时适配信任证书

    转载请注明出处: 1.http协议请求 使用RestTemplate进行http协议的请求时,不需要考虑证书验证相关问题,以下为使用RestTemplate直接使用的代码示例: import org. ...

  4. 重新点亮shell————sed的替换[十]

    前言 简单介绍一下sed 和 awk. 正文 这两个和vim的区别: vim 是交互式和 他们是非交互式 vim是文件操作模式与他们是行交互模式 sed sed 的 模式空间. sed的基本工作方式是 ...

  5. 深度解读《深度探索C++对象模型》之返回值优化

    接下来我将持续更新"深度解读<深度探索C++对象模型>"系列,敬请期待,欢迎关注!也可以关注公众号:iShare爱分享,自动获得推文和全部的文章列表. 没有启用返回值优 ...

  6. 关于console.log中this指向的问题

  7. 力扣579(MySQL)-查询员工的累积薪水(困难)

    题目: Employee 表保存了一年内的薪水信息. 请你编写 SQL 语句,对于每个员工,查询他除最近一个月(即最大月)之外,剩下每个月的近三个月的累计薪水(不足三个月也要计算). 结果请按 Id ...

  8. 如何将传统 Web 框架迁移部署到 Serverless 架构?

    简介: 与其说 Serverless 架构是一个新的概念,不如说它是一种全新的思路,一种新的编程范式. 与其说 Serverless 架构是一个新的概念,不如说它是一种全新的思路,一种新的编程范式. ...

  9. 【USENIX ATC】支持异构GPU集群的超大规模模型的高效的分布式训练框架Whale

    简介: 高效大模型训练框架Whale(EPL)入选USENIX ATC 作者:张杰.贾贤艳 近日,阿里云机器学习PAI关于深度学习模型高效的分布式训练框架的论文< Whale: Efficien ...

  10. 急速上线 Serverless 钉钉机器人“防疫精灵”

    新型冠状病毒疫情肆虐的春节,大家都过得人心惶惶,作为被关在家的程序狗,总觉得要做点什么.于是阿里云 IoT 事业部的几个同学就开始了防疫精灵的开发之路. 从点子到防疫宝,只花了一个下午时间:从防疫宝到 ...