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
     


  • 相关阅读:
    [译]JavaScript源码转换:非破坏式与再生式
    [译]ES6中的代理对象
    tensorflow 如何获取graph中的所有tensor name
    python3中的str和bytes
    git submodule 添加 更新 删除 教程
    《重构:改善既有代码的设计》摘抄
    thrift入门教程/thrift资料集合
    将python2代码升级为python3代码最佳实践
    python标准库:subprocess——子进程管理
    安装“python-snappy”遇到“error: command 'x86_64-linux-gnu-gcc' failed with exit status 1”
  • 原文地址:https://www.cnblogs.com/jjzd/p/6517432.html
Copyright © 2011-2022 走看看