zoukankan      html  css  js  c++  java
  • SELinux

    selinux - NSA Security-Enhanced Linux (SELinux)

    SELinux工作在内核当中,伪目录 /selinux/,进程工作在SELinux中,就好比工作在沙箱当中,进程能访问那些文件,权限由SELinux规则决定,SELinux的目的就是让进程拥有最小化权限。

    1、启用或关闭selinux

    查看当前是否启用:

    [root@myhost01 tmp]# getenforce
    Disabled

    状态:

    Enforcing:启用状态,当进程访问了没有权限访问的文件时会被禁止并记录到日志,/var/log/audit/audit.log。

    Permissive:工作在正常状态下,当进程访问了没有权限访问的文件,不会被禁止,仅仅记录到日志。

    Disabled:永久关闭selinux,/etc/sysconfig/selinux,SELINUX=disabled,改完之后重启系统才会生效。

    setenforce 0:临时关闭selinux对操作的影响,实际上修改的是/selinux/enforce文件,所以也可以echo 0 > /selinux/enforce进行关闭。

    2、对文件进行修改类型,上下文  Labeling files

    ls -Z 可以看到文件的SELinux属性,分别是user,role,type文件类型

    创建/tmp/selinux.txt,修改SELinux类型为var_log_t

    chcon:chcon - change file SELinux security context

    -t, --type=TYPE
                  set type TYPE in the target security context
    -R, --recursive,递归目录
                  operate on files and directories recursively
    --reference=RFILE
                  use RFILE’s security context rather than specifying a CONTEXT value

    [root@myhost01 tmp]# ls -Z
    -rw-r--r-- root root ?                                selinux.txt
    [root@myhost01 tmp]# chcon --reference=/var/log/anaconda.log /tmp/selinux.txt
    [root@myhost01 tmp]# ls -Z /tmp/
    -rw-r--r--. root root system_u:object_r:var_log_t:s0   selinux.txt
    [root@myhost01 tmp]# chcon -t consolekit_log_t  /tmp/selinux.txt
    [root@myhost01 tmp]# ls -Z /tmp/
    -rw-r--r--. root root system_u:object_r:consolekit_log_t:s0 selinux.txt
    [root@myhost01 tmp]#

    context被改乱了,可以恢复默认

    restorecon - restore file(s) default SELinux security contexts.

    restorecon filename


    selinux运行时修改bool开关

    getsebool -a 查看

    samba正常工作

    setsebool samba_enable_home_dirs=0或off    1或on

    3、semanage

    semanage fcontext -l 列出在哪些目录下创建文件的默认类型。

    semanage user -l 列出建立的selinux用户

    semanage port -l 列出受selinux控制的端口

    加入受管理端口:semanage port -a -t http_port_t -p tcp 8989
     


  • 相关阅读:
    构建业务用例
    CentOS 7使用Redis Cluster
    pymysql.err.OperationalError: (1054, "Unknown column 'aa' in 'field list'")(已解决)
    Flask框架实现登录注册功能(mysql数据库)
    C#实现登录功能(连接SQLServer数据库)
    大数据智能加工系统——纸上原型分析
    Windows环境下启动Redis报错:Could not create server TCP listening socket 127.0.0.1:6379: bind: 操作成功完成。(已解决)
    HBase数据库基础操作
    决策树——非正常企业数目预测
    MongoDB启动报错:Unrecognized option: storage try 'mongod --help' for more information(已解决)
  • 原文地址:https://www.cnblogs.com/jjzd/p/6517432.html
Copyright © 2011-2022 走看看