CentOS 7 系统优化之关闭 SELinux
SELinux 背景很强大,它由美国国家安全局开发。英文全称是 Security-Enhanced Linux 简称为 SELinux 。SELinux 是 2.6 版本的 Linux 内核中提供的强制访问控制系统。它默认安装在 Linux 系统中,是一个内核模块,是系统中的安全子系统。简单来说,就是用它来限制系统中用户权限。本文主要介绍通过关闭 SELinux 优化服务器 CentOS 7 系统,关闭方式分为 2 种,临时关闭和永久关闭。
一、查看 SELinux 状态
使用getenforce命令,查看 SELinux 状态,操作如下。
[root@centos7 ~]# getenforceEnforcing[root@centos7 ~]#
执行命令后,返回值表示:
- Enforcing 表示 SELinux 正在运行。
- Permissive 表示 SELinux 临时关闭,但仍然会提示警告。
- Disabled 表示 SELinux 永久关闭。
二、临时关闭 SELinux
使用setenforce命令,临时关闭 SELinux ,操作如下。
[root@centos7 ~]# setenforceusage: setenforce [ Enforcing | Permissive | 1 | 0 ][root@centos7 ~]# setenforce 0[root@centos7 ~]# getenforcePermissive[root@centos7 ~]#
执行setenforce命令后,提示setenforce命令有 2 种使用方法:
执行
setenforce 0或setenforce permissive命令,表示临时关闭 SELinux 。执行
setenforce 1或setenforce enforcing命令,表示开启 SELinux 。
但是setenforce命令,无法把 SELinux 状态改为 Disabled 永久关闭。
当使用临时关闭 SELinux 时,重启系统后 SELinux 会自动重新启动。
三、 永久关闭 SELinux
使用vim命令,编辑/etc/selinux/config文件,永久关闭 SELinux ,操作如下。
[root@centos7 ~]# 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# 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
把第 8 行的SELINUX=enforcing改为SELINUX=disabled后保存退出,重启系统后设置生效。
如果想检查修改是否成功,使用grep命令,搜索文件内容是否包含=disabled,操作如下。
[root@centos7 ~]# grep "=disabled" /etc/selinux/configSELINUX=disabled[root@centos7 ~]#
到此,修改成功。重启系统即可。
四、参考文献
百度百科:https://baike.baidu.com/item/SELinux
(完)