CentOS 7 关闭 selinux

  1. 要关掉selinux,首先要查看它是否运行。输入/usr/sbin/sestatus -v查看状态
[root@localhost ~]# /usr/sbin/sestatus -v
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

Process contexts:
Current context:                unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
Init context:                   system_u:system_r:init_t:s0
/usr/sbin/sshd                  system_u:system_r:sshd_t:s0-s0:c0.c1023

File contexts:
Controlling terminal:           unconfined_u:object_r:user_devpts_t:s0
/etc/passwd                     system_u:object_r:passwd_file_t:s0
/etc/shadow                     system_u:object_r:shadow_t:s0
/bin/bash                       system_u:object_r:shell_exec_t:s0
/bin/login                      system_u:object_r:login_exec_t:s0
/bin/sh                         system_u:object_r:bin_t:s0 -> system_u:object_r:shell_exec_t:s0
/sbin/agetty                    system_u:object_r:getty_exec_t:s0
/sbin/init                      system_u:object_r:bin_t:s0 -> system_u:object_r:init_exec_t:s0
/usr/sbin/sshd                  system_u:object_r:sshd_exec_t:s0

SELinux status:
* enabled就是开启的;
* disabled就是关闭

  1. 开启的时候我们还需要看它的模式(Current mode),它有三种模式
    • enforcing:强制模式,代表 SELinux 运作中,且已经正确的开始限制 domain/type 了;
    • permissive:宽容模式:代表 SELinux 运作中,不过仅会有警告讯息并不会实际限制 domain/type 的存取。
    • disabled:关闭,SELinux 并没有实际运作。
      在不重系统的情况下就是将模式改为permissive
setenforce 0

但是,这样关掉会有一个问题,就是系统重起后,会恢复为enforcing模式,所以还需要修改配置文件

  1. 修改配置文件重启系统关闭selinux
    修改/etc/selinux/config 文件。将SELINUX=enforcing 改为SELINUX=disable
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=disable
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

你可能感兴趣的:(CentOS 7 关闭 selinux)