【linux系统优化】Selinux介绍及关闭方法

Selinux:SELinux(Security-EnhancedLinux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统。linux

虽然是一个安全功能,但是因为功能太多了,什么都要管,因此用起来反而更麻烦,于是能够把它关闭,进而使用其它的安全方式替代。安全


【1】查看Selinux运行的3种模式编辑器

[root@moban ~]#cat /etc/selinux/config     #此为Selinux的配置文件目录
# This filecontrols the state of SELinux on the system.
# SELINUX= cantake one of these three values:
#     enforcing - SELinux security policy isenforced.
#     permissive - SELinux prints warningsinstead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE=can take one of these two values:
#     targeted - Targeted processes areprotected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

能够看到有3种运行模式:ide

enforcing:开启Selinux
permissive:自由模式,此种模式下,只会打印警告消息,但不会阻止
disabled:关闭Selinux

【2】更改Selinux配置文件的运行模式spa

方法一:使用vi文件编辑器修改code

[root@moban ~]# vi /etc/selinux/config

将“SELINUX=enforcing”修改成“SELINUX=disabled”,保存退出便可three

方法二:sed命令ci

[root@moban ~]#sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/conf
[root@moban ~]#grep "disabled" /etc/selinux/config
#     disabled - No SELinux policy is loaded.
SELINUX=disabled

注意必定要加参数-i,不然只改变输出,而不是改变配置文件的内容。可是须要注意的是,因为修改Selinux的配置文件须要在下一次重启后才生效,所以当前Selinux实际运行状态还是enforcing,因此须要再进行一些设置。(为了避免重启Linux系统)get


3】更改Selinux的当前运行模式it

查看当前运行模式:

[root@moban ~]#getenforce  
Enforcing

将当前模式修改成permissive状态:

[root@moban ~]# setenforce 0
[root@moban ~]#getenforce  
Permissive

注意到此时已经将当前Selinux的运行模式改变为permissive状态,若是仍需改回enforcing状态则输入setenforce 1便可,但注意setenforce只有参数0和1:

[root@moban ~]#setenforce 1
[root@moban ~]#getenforce  
Enforcing
[root@moban ~]# setenforce2
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]

改成permissive状态后,虽然会打印警告消息,但对实际操做是没有影响的,因此能够达到目的。

由此可知,以上两种修改方式,第一种为永久修改,第二种为临时修改。

相关文章
相关标签/搜索