• Selinux


    1.查看selinux是否开启

    SELinux的状态:

    - enforcing:强制,每个受限的进程都必然受限
    - permissive:允许,每个受限的进程违规操作不会被禁止,但会被记录于审计日志
    - disabled:禁用

    相关命令:

    • - getenforce: 获取selinux当前状态
    • - sestatus :查看selinux状态
    • - setenforce 0|1 
    •   - 0: 设置为permissive ###宽容模式
    •   - 1: 设置为enforcing ###强制

    [root@localhost html]#getenforce 
    Enforcing


    如果没有开启可以使用以下命令开启
    [root@localhost html]#setenforce 1


    永久开启需要修改  此处文件  /etc/selinux/config
    vim /etc/selinux/config
    # 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=enforcing

    2.文件类型 

     3.seinfo

    1. [root@localhost ~]# seinfo -t
    2. bash: seinfo: 未找到命令...
    3. [root@localhost ~]# yum provides seinfo
    4. 已加载插件:fastestmirror, langpacks
    5. Loading mirror speeds from cached hostfile
    6. * base: mirrors.bfsu.edu.cn
    7. * extras: mirrors.bfsu.edu.cn
    8. * updates: mirrors.bfsu.edu.cn
    9. extras/7/x86_64/filelists_db | 303 kB 00:00:00
    10. setools-console-3.3.8-4.el7.x86_64 : Policy analysis command-line tools for SELinux
    11. 源 :base
    12. 匹配来源:
    13. 文件名 :/usr/bin/seinfo

    [root@localhost ~]# yum install setools-console-3.3.8-4.el7.x86_64 -y
    

    1. [root@localhost ~]# seinfo -a
    2. Attributes: 256
    3. cert_type
    4. privfd
    5. file_type
    6. boinc_domain
    7. cfengine_domain
    8. wine_domain

     4.修改文件类型

    1.7-2查看httpd进程

    1. [root@localhost html]# ls -Z
    2. -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
    3. [root@localhost html]#
    4. [root@localhost html]# ps auxZ|grep httpd ###过滤httpd进程
    5. system_u:system_r:httpd_t:s0 root 51859 0.0 0.2 221952 4996 ? Ss 13:50 0:00 /usr/sbin/httpd -DFOREGROUND
    6. system_u:system_r:httpd_t:s0 apache 51860 0.0 0.1 224036 3104 ? S 13:50 0:00 /usr/sbin/httpd -DFOREGROUND
    7. system_u:system_r:httpd_t:s0 apache 51861 0.0 0.1 224036 3104 ? S 13:50 0:00 /usr/sbin/httpd -DFOREGROUND

    2.用7-1curl访问7-2

    1. [root@localhost html]# ls
    2. index.html
    3. [root@localhost html]#
    4. [root@localhost html]# ls -Z
    5. -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
    6. [root@localhost html]#

    3.在7-2中修改文件类型 

    1. [root@localhost html]# chcon -t var_t /var/www/html/index.html
    2. [root@localhost html]#
    3. [root@localhost html]# ls -Z
    4. -rw-r--r--. root root unconfined_u:object_r:var_t:s0 index.html
    5. [root@localhost html]#

    4.开一下selinux

    1. [root@localhost html]# getenforce
    2. Permissive
    3. [root@localhost html]# setenforce 1
    4. [root@localhost html]# getenforce
    5. Enforcing
    6. [root@localhost html]#

    5.用7-1再去访问index.html页面

    6.把selinux关掉

    [root@localhost html]# setenforce 0
    

    7.用7-1再去访问一下

    1. [root@localhost ~]# curl 192.168.91.102
    2. 7-2

    5.去7-3改端口

    1.先把selinux开启

    1. [root@localhost html]# setenforce 1
    2. [root@localhost html]# getenforce
    3. Enforcing
    4. [root@localhost html]#

    2.去主配置文件中加端口

    1. [root@localhost html]# vim /etc/httpd/conf/httpd.conf
    2. [root@localhost html]#
    3. [root@localhost html]# systemctl restart httpd
    4. Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
    5. [root@localhost html]#

    3.解决进程与端口绑定问题

    1. [root@localhost html]# semanage port -a -t http_port_t -p tcp 9527
    2. [root@localhost html]#
    3. [root@localhost html]# systemctl restart httpd
    4. [root@localhost html]#

    6.selinux的配置文件

    [root@localhost html]# vim /etc/selinux/config

  • 相关阅读:
    分类预测 | Matlab实现基于LFDA-SVM局部费歇尔判别数据降维结合支持向量机的多输入分类预测
    【含java2023面试题】HashMap、HashTable、ConcurrentHashMap
    【C++函数的进化】函数指针,模板,仿函数,lambda表达式
    Python构建学生信息管理系统:需求分析与规划
    线程池优化
    19 学生端注册与登录
    使用keytool生成Tomcat证书
    【快手面试】Word2vect生成的向量,为什么可以计算相似度,相似度有什么意义?
    VUE-Router前置理由守卫实现账号登陆页面访问权限权限
    Allegro Design Entry HDL(OrCAD Capture HDL)模块管理菜单详细介绍
  • 原文地址:https://blog.csdn.net/YUEAwb/article/details/136505331