• selinux详解及配置文件


    selinux详解

    selinux 的全称是Security Enhance Linux,就是安全加强的Linux。在Selinux之前root账号能够任意的访问所有文档和服务 ;

    如果某个文件设为777,那么任何用户都可以访问甚至删除。 这种方式称为DAC(主动访问机制),很不安全。

    DAC自主访问控制: 用户根据自己的文件权限来决定对文件的操作,也就是依据文件的own,group,other/r,w,x 权限进行限制。Root有最高权限无法限制。r,w,x权限划分太粗糙。无法针对不同的进程实现限制。

    Selinux则是基于MAC(强制访问机制),简单的说,就是程序和访问对象上都有一个安全标签(即selinux上下文)进行区分,只有对应的标签才能允许访问,否则即使权限是777,也是不能访问的。

    在selinux中,访问控制属性叫做安全上下文,所有客体(文件、进程间通讯通道、套接字、网络主机等)和主体(进程)都有与其关联的安全上下文,一个安全上下文由三部分组成:用户(u)、角色(r)、和类型(t)标识符。但我们最关注的是第三部分

    当程序访问资源时 ,主体程序必须要通过selinux策略内的规则放行后,就可以与目标资源进行安全上下文的比对,若比对失败则无法存取目标,若比对成功则可以开始存取目标,最终能否存取目标还要与文件系统的rwx权限的设定有关,所以启用了selinux后出现权限不符的情况时,你就得一步一步分析可能出现的问题了。

    1.selinux状态查看与配置:

    selinux的配置文件位置:/etc/selinux/config,它还有个链接在/etc/sysconfig/selinux.

    使用config文件来配置selinux(通过配置文件修改selinux的状态属于永久修改,要重启系统才生效)

    [root@localhost ~]# ls /etc/sysconfig/selinux  -l
    lrwxrwxrwx. 1 root root 17 Jan 10 19:48 /etc/sysconfig/selinux -> ../selinux/config

    (1)配置文件

    [root@make_blog ~]# cat /etc/sysconfig/selinux
    
    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=disabled
    # SELINUXTYPE= can take one of three two values:
    #     targeted - Targeted processes are protected,
    #     minimum - Modification of targeted policy. Only selected processes are protected. 
    #     mls - Multi Level Security protection.
    SELINUXTYPE=targeted

    selinux=enforcing

    #此项定义selinux状态

    #enforcing-是强制模式系统,它受selinux保护。就是违反了策略你就无法继续操作下去。

    #permissive-是提示模式系统不会受到selinux保护,只是收到警告信息。permissive就是selinux有效,但是即使你违反了策略的话它让你继续操作,但是把你违反的内容记录下来(警告信息)

    #disabled-禁用selinux

    selinuxtype=targeted

    #此项定义selinux使用哪个策略模块保护系统。targeted只对Apache,sendmail,bind,postgresql,nfs,cifs等网络服务保护。

    以上策略配置都放置在/etc/selinux目录中,目录和策略名称相同。

    使用selinux相关命令查看和修改状态:(属于立即生效但临时性的)

    (2)查看工作状态

    getenforce查看selinux状态

    [root@make_blog ~]# getenforce 
    Disabled
    

    setenforce设定selinux运行状态,1开启(Enforce),0关闭(Permissive)

    [root@localhost datas]# setenforce 
    usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
    
    [root@localhost ~]# setenforce  0
    [root@localhost ~]# getenforce 
    Permissive
    [root@localhost ~]# setenforce 1
    [root@localhost ~]# getenforce 
    Enforcing

     相关链接:https://blog.csdn.net/kangshuo2471781030/article/details/79294506

  • 相关阅读:
    linux异常文件下载
    spring boot项目发布到tomcat端口问题
    jenkins.service changed on disk. Run 'systemctl daemon-reload' to reload units
    Job for jenkins.service failed because the control process exited with error code
    安装配置jenkins rpm方式
    Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed w
    Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environ
    Cannot find class: org.mybatis.caches.ehcache.LoggingEhcache
    java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
    Error:(12, 8) java: 无法访问javax.servlet.ServletException 找不到javax.servlet.ServletException的类文件
  • 原文地址:https://www.cnblogs.com/yinfutao/p/10613083.html
Copyright © 2020-2023  润新知