SELinux配置

    openEuler默认使用SELinux提升系统安全性。SELinux分为三种模式:

    • permissive:SELinux仅打印告警而不强制执行。
    • enforcing:SELinux安全策略被强制执行。
    • disabled:不加载SELinux安全策略。
    • 获取当前SELinux运行状态:

      1. # getenforce
      2. Enforcing
    • SELinux开启的前提下,设置运行状态为permissive模式:

      1. # setenforce 0
      2. # getenforce
      3. Permissive
    • SELinux开启的前提下,设置当前SELinux运行状态为disabled(关闭SELinux,需要重启系统)。

      1. 修改SELinux配置文件/etc/selinux/config,设置“SELINUX=disabled”。
        1. SELINUX=disabled
      2. 重启系统:
        1. # reboot
      3. 状态切换成功:
      1. 修改SELinux配置文件/etc/selinux/config,设置“SELINUX=permissive”:
        1. # cat /etc/selinux/config | grep "SELINUX="
      2. 在根目录下创建.autorelabel文件:
        1. # touch /.autorelabel
      3. 重启系统,此时系统会重启两次:
        1. # reboot
      4. 状态切换成功:
        1. # getenforce
        2. Permissive
    • SELinux关闭的前提下,设置SELinux运行状态为enforcing:

      1. 按照上一步骤所述,设置SELinux运行状态为permissive。
      2. 修改SELinux配置文件/etc/selinux/config,设置“SELINUX=enforcing”:
      3. 状态切换成功:
        1. # getenforce
        2. Enforcing
    • 查询运行SELinux的系统状态。SELinux status表示SELinux的状态,enabled表示启用SELinux,disabled表示关闭SELinux。Current mode表示SELinux当前的安全策略。

      1. # sestatus
      2. SELinux status: enabled
      3. SELinux root directory: /etc/selinux
      4. Loaded policy name: targeted
      5. Current mode: enforcing
      6. Mode from config file: enforcing
      7. Policy MLS status: enabled
      8. Policy deny_unknown status: allowed
      9. Memory protection checking: actual (secure)
      10. Max kernel policy version: 31
      1. dnf update selinux-policy -y