本文共 1728 字,大约阅读时间需要 5 分钟。
Selinux:SELinux(Security-EnhancedLinux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统。
虽然是一个安全功能,可是由于功能太多了,什么都要管,所以用起来反而更麻烦,因而可以把它关闭,进而使用其它的安全方式替代。
【1】查看Selinux运行的3种模式
1 2 3 4 5 6 7 8 9 10 11 | [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种运行模式:
1 2 3 | enforcing:开启Selinux permissive:自由模式,此种模式下,只会打印警告消息,但不会阻止 disabled:关闭Selinux |
【2】更改Selinux配置文件的运行模式
方法一:使用vi文件编辑器修改
1 | [root@moban ~]# vi /etc/selinux/config |
将“SELINUX=enforcing”修改为“SELINUX=disabled”,保存退出即可
方法二:sed命令
1 2 3 4 | [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系统)
【3】更改Selinux的当前运行模式
查看当前运行模式:
1 2 | [root@moban ~]#getenforce Enforcing |
将当前模式修改为permissive状态:
1 2 3 | [root@moban ~]# setenforce 0 [root@moban ~]#getenforce Permissive |
注意到此时已经将当前Selinux的运行模式改变为permissive状态,如果仍需改回enforcing状态则输入setenforce 1即可,但注意setenforce只有参数0和1:
1 2 3 4 5 | [root@moban ~]#setenforce 1 [root@moban ~]#getenforce Enforcing [root@moban ~]# setenforce2 usage: setenforce [ Enforcing | Permissive | 1 | 0 ] |
改为permissive状态后,虽然会打印警告消息,但对实际操作是没有影响的,所以可以达到目的。
由此可知,以上两种修改方式,第一种为永久修改,第二种为临时修改。
转载地址:http://oeslo.baihongyu.com/