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. HuffmanTree,哈夫曼树的原理和c++实现

    目录 一.什么是哈夫曼树 二.构造哈夫曼树 三.路径.编码.解码 四.代码 一.什么是哈夫曼树 哈夫曼树又称为最优树. 通过权值来构造树,权值越大,离根节点越近 经常用于无损压缩算法 用于需要优化存储 ...

  2. Python3学习--正则表达式

    import rer = re.match("Chen\d+","Chen123ronghua123")r = re.match(".+", ...

  3. 重新整理 .net core 实践篇—————微服务的桥梁EventBus[三十一]

    前言 简单介绍一下EventBus. 正文 EventBus 也就是集成事件,用于服务与服务之间的通信. 比如说我们的订单处理事件,当订单处理完毕后,我们如果通过api马上去调用后续接口. 比如说订单 ...

  4. linux 连接wifi

    前言 我使用树莓派的时候实际过的. 正文 第一步扫描wifi: iwlist wlan0 scan 然后配置: vim /etc/wpa_supplicant/wpa_supplicant.conf ...

  5. 在windows电脑中安装redis

    1,github下载地址:https://github.com/MSOpenTech/redis/tags 2,下载完成后,解压到对应文件夹 3,打开redis.windows.conf,在#requ ...

  6. Elasticsearch与kibana的单机安装

    前言 本文为纯实操记录,以供需要时查阅. 对应版本为7.3,jdk版本1.8 Elasticsearch安装 Elasticsearch官网:https://www.elastic.co/cn/pro ...

  7. Jenkins实战系列(一)——Jenkins简介

    Jenkins是一个开源的自动化构建工具,可以帮助开发人员自动构建.测试和部署软件.它支持多种编程语言.版本控制系统和构建工具,如Java.Git.Maven等.Jenkins的核心功能是通过一系列插 ...

  8. 修改中文、英文参考文献在文末列表中的顺序:EndNote

      本文介绍在EndNote软件中,使得参考文献按照语种排列,中文在前.英文在后的方法.   前期我们在EndNote参考文献格式Output Styles界面介绍一文中,详细介绍了文献管理软件End ...

  9. [Go] 注意 go build -o <output> 选项的准确含义

    -o <output> 选项强制执行把构建的可执行文件写入到目标文件或者目标目录中. 如果 output 是已存在的目录,那么所有构建好的文件都将写入到该目录中. 注意:如果目录不存在的话 ...

  10. 2018-8-10-WPF-省市县3级联动

    title author date CreateTime categories WPF 省市县3级联动 lindexi 2018-08-10 19:16:53 +0800 2018-2-13 17:2 ...