博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【linux系统优化】Selinux介绍及关闭方法
阅读量:6709 次
发布时间:2019-06-25

本文共 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/

你可能感兴趣的文章
SQL经典语句大全之五
查看>>
cacti监控(1)基础安装apache mysql php
查看>>
增强wordpress安全
查看>>
Oracle数据库部署
查看>>
mysql5.6的icp索引
查看>>
2014年IT行业11大安全风险值得警惕
查看>>
Spring Boot 常用注解深入
查看>>
ThreadLocal 实现原理
查看>>
一些网址
查看>>
这个开关可以有
查看>>
ocjp 考试题之四
查看>>
如何查看android.jar中的xml文件
查看>>
spring aop 功能初次使用(注解方式)
查看>>
Openfiler配置iSCSI应用
查看>>
nginx服务脚本
查看>>
SpringCloud微服务间安全调用实现(SpringSecurity+Oauth2+Jwt)
查看>>
我的友情链接
查看>>
kettle整合到web项目并运用quartz实现定时任务
查看>>
Spark SQL 查询人口数量与平均年龄实验
查看>>
linux find基本用法
查看>>