zoukankan      html  css  js  c++  java
  • linux(centos8):禁用selinux(临时关闭/永久关闭)

    一,selinux的用途

    1,什么是selinux

    SELinux:即安全增强型 Linux(Security-Enhanced Linux)

    它是一个 Linux 内核模块,也是 Linux 的一个安全子系统

    它主要由美国国家安全局开发,

    它的主要作用:最大限度地减小系统中服务进程可访问的资源(最小权限原则)

    2,为什么要关闭selinux?

    有的软件对于selinux的安全规则支持不够好,就会建议在安装前把selinux先关闭,

    例如:k8s:

    附:k8s的相应说明:

    Setting SELinux in permissive mode by runningsetenforce 0andsed ...effectively disables it.
    This is required to allow containers to access the host filesystem, which is needed by pod networks for example.
    You have to do this until SELinux support is improved in the kubelet...

    其目的在于允许容器访问宿主机的文件系统,

    这种情况下只能先关闭selinux

    说明:如果不是要运行的软件有相应需求,不建议关闭selinux

    说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

             对应的源码可以访问这里获取: https://github.com/liuhongdi/

    说明:作者:刘宏缔 邮箱: 371125307@qq.com

    二,查看当前selinux的状态?

    1,selinux的三种运行模式:

    enforcing:强制模式,SELinux 正在运行中,已经在限制 domain/type

    permissive:宽容模式:SELinux 正在运行中,但仅发出警告信息,并不会实际限制 domain/type 的存取

    (permissive模式可以用在测试环境中供调试规则时使用)

    disabled:关闭,SELinux 没有实际运行。

    2,用sestatus查看

    [liuhongdi@centos8 ~]$ sestatus -v
    SELinux status:                 enabled
    SELinuxfs mount:                /sys/fs/selinux
    SELinux root directory:         /etc/selinux
    Loaded policy name:             targeted
    Current mode:                   enforcing
    Mode from config file:          enforcing
    Policy MLS status:              enabled
    Policy deny_unknown status:     allowed
    Memory protection checking:     actual (secure)
    Max kernel policy version:      31
    ...

    可以看到: Current mode:                   enforcing

    3,用getenforce查看(常用)

    [liuhongdi@centos8 ~]$ getenforce 
    Enforcing

    三,临时关闭/开启selinux

    查看当前的运行模式

    [root@centos8 liuhongdi]# getenforce 
    Enforcing

    配置selinux运行模式为:Permissive

    #0: Permissive

    #1: Enforcing

    [root@centos8 liuhongdi]# setenforce 0

    查看效果:

    [root@centos8 liuhongdi]# getenforce 
    Permissive

    四,永久关闭selinux

    1, 修改配置文件

    [root@centos8 liuhongdi]# vi /etc/selinux/config 

    设置配置项为:

    SELINUX=disabled

    说明:默认值是: #SELINUX=enforcing

    然后重启机器

    2,修改/etc/sysconfig/selinux 这个文件也可以生效

       因为它其实就是/etc/selinux/config的符号链接

    [root@centos8 liuhongdi]# ll /etc/sysconfig/selinux 
    lrwxrwxrwx. 1 root root 17 11月 11 2019 /etc/sysconfig/selinux -> ../selinux/config

    五,selinux的相关知识:

    1,selinux默认的审计日志位于:/var/log/audit/audit.log

    [root@centos8 ~]# ll /var/log/audit/audit.log
    -rw------- 1 root root 5093679 5月  29 13:57 /var/log/audit/audit.log

    2,如何分析selinux的日志?

    #-a:--analyze=FILE:   分析一个文件

    [root@centos8 ~]# sealert -a /var/log/audit/audit.log

    3,查询系统中的布尔型规则及其状态

    [root@centos8 liuhongdi]# getsebool -a

    六,查看linux的版本

    [liuhongdi@centos8 ~]$ cat /etc/redhat-release 
    CentOS Linux release 8.1.1911 (Core) 
  • 相关阅读:
    Android学习笔记03:学习过程中碰到的一些问题及解决方法
    写于莫言获得诺贝尔文学奖之际
    Windows环境下QT学习笔记01:QT及QT Creator的下载及安装
    Android学习笔记02:AndroidManifest.xml源码
    Android学习笔记01:开发环境搭建
    怀念我的大学四年
    喜获TI MSP430 LaunchPad开发板
    Win7下VS2008破解方法
    手把手教你把Vim改装成一个IDE编程环境
    顺序线性表
  • 原文地址:https://www.cnblogs.com/architectforest/p/12987499.html
Copyright © 2011-2022 走看看