SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled) 几种模式之间的转换

在Android的root相关的文章里经常会看到关于SElinux,Android4.3以后引进SElinux。

###SELinux 的启动、关闭与查看

1、并非所有的 Linux distributions 都支持 SELinux

目前 SELinux 支持三种模式,分别如下:

•enforcing:强制模式,代表 SELinux 运作中,且已经正确的开始限制 domain/type 了;

•permissive:宽容模式:代表 SELinux 运作中,不过仅会有警告讯息并不会实际限制 domain/type 的存取。这种模式可以运来作为 SELinux 的 debug 之用;

•disabled:关闭,SELinux 并没有实际运作。

2,查看SELinux的模式

# getenforce Enforcing <==就显示出目前的模式为 Enforcing

3,查看 SELinux 的政策 (Policy)?

[root@master oracle]# sestatus

SELinux status: enabled <==是否启动 SELinux

SELinuxfs mount: /selinux <==SELinux 的相关文件资料挂载点

Current mode: enforcing <==目前的模式

Mode from config file: enforcing <==设定档指定的模式

Policy version: 21

Policy from config file: targeted <==目前的政策为何?

4,通过配置文件调整SELinux的参数

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

SELINUX=enforcing <==调整 enforcing|disabled|permissive

SELINUXTYPE=targeted <==目前仅有 targeted 与 strict

5,SELinux 的启动与关闭

【重要常识】上面是预设的政策与启动的模式!你要注意的是,如果改变了政策则需要重新开机;如果由 enforcing 或 permissive 改成 disabled ,或由 disabled 改成其他两个,那也必须要重新开机。这是因为 SELinux 是整合到核心里面去的, 你只可以在 SELinux 运作下切换成为强制 (enforcing) 或宽容 (permissive) 模式,不能够直接关闭 SELinux 的!

同时,由 SELinux 关闭 (disable) 的状态到开启的状态也需要重新开机啦!所以,如果刚刚你发现 getenforce 出现 disabled 时, 请到上述文件修改成为 enforcing 吧!

【重点】如果要启动SELinux必须满足以下两个点:

所以,如果你要启动 SELinux 的话,请将上述的 SELINUX=enforcing 设定妥当,并且指定 SELINUXTYPE=targeted 这一个设定, 并且到 /boot/grub/menu.lst 这个文件去,看看核心有无关闭 SELinux 了呢?

[root@www ~]# vi /boot/grub/menu.lst

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title CentOS (2.6.18-92.el5)

root (hd0,0)

kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/1 rhgb quiet selinux=0

initrd /initrd-2.6.18-92.el5.img

如果要启动 SELinux ,则不可以出现 selinux=0 的字样在 kernel 后面!

【问题】通过上面的学习我们知道,如果将启动着的SELinux改为禁用,需要重启电脑,我们不想重启电脑又不想开启SELinux该怎么办呢?

【答案】将强制模式改为宽松模!

[root@www ~]# setenforce [0|1]

选项与参数:

0 :转成 permissive 宽容模式;

1 :转成 Enforcing 强制模式

范例一:将 SELinux 在 Enforcing 与 permissive 之间切换与查看

[root@www ~]# setenforce 0

[root@www ~]# getenforce Permissive

[root@www ~]# setenforce 1

[root@www ~]# getenforce Enforcing

6,查看已启动程序的type设定

[root@master oracle]# ps aux -Z

LABEL USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

system_u:system_r:init_t root 1 0.0 0.4 2060 520 ? Ss May07 0:02 init [5 system_u:system_r:kernel_t root 2 0.0 0.0 0 0 ? S< May07 0:00 [migra] system_u:system_r:kernel_t root 11 0.0 0.0 0 0 ? S< May07 0:00 [kacpi] system_u:system_r:auditd_t root 4022 0.0 0.4 12128 560 ? S

说明:其实这些东西我们都不用管,都是SELinux内置的。只要学会在强制和宽松模式间转换就行了!

小结附:

关闭SELinux的方法:

修改/etc/selinux/config文件中的SELINUX="" 为 disabled ,然后重启。

如果不想重启系统,使用命令setenforce 0

注:

setenforce 1 设置SELinux 成为enforcing模式

setenforce 0 设置SELinux 成为permissive模式

在lilo或者grub的启动参数中增加:selinux=0,也可以关闭selinux

#---------------------------------------------------------------

查看selinux状态:

/usr/bin/setstatus -v

如下:

SELinux status:                 enabled

SELinuxfs mount:                /selinux

Current mode:                   permissive

Mode from config file:          enforcing

Policy version:                 21

Policy from config file:        targeted

getenforce/setenforce查看和设置SELinux的当前工作模式

#-----------------------------------------------------------------------

查看SELinux状态:

1、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态

SELinux status: enabled

2、getenforce ##也可以用这个命令检查

关闭SELinux:

1、临时关闭(不用重启机器):

setenforce 0 ##设置SELinux 成为permissive模式

##setenforce 1 设置SELinux 成为enforcing模式

1

2、修改配置文件需要重启机器:

修改/etc/selinux/config 文件

将SELINUX=enforcing改为SELINUX=disabled

重启机器即可

linux宽松模式,SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled) 几种模式之间的转换...相关推荐

  1. SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled) 几种模式之间的转换

    SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled) 几种模式之间的转换 SELinux 的启动.关闭与查看 1.并非所有的 Linux dist ...

  2. SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled) 几种模式之间的转换...

    http://blog.sina.com.cn/s/blog_5aee9eaf0100y44q.html 在CentOS6.2 中安装intel 的c++和fortran 的编译器时,遇到来一个关于S ...

  3. mysql 宽容模式_SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled)  几种模式之间的转换...

    在CentOS6.2 中安装intel 的c++和fortran 的编译器时,遇到来一个关于SELinux的强制模式不可执行的情况, 需要关闭SELinux 或者 将enforcing改为 permi ...

  4. SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled)

    SElinux共有3中状态.1.selinux的配置文件:/etc/selinux/config# This file controls the state of SELinux on the sys ...

  5. mysql 宽容模式_SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled)

    SElinux共有3中状态. 1.selinux的配置文件:/etc/selinux/config # This file controls the state of SELinux on the s ...

  6. oracle关闭的四种模式

    1.关闭数据库需要权限:SYSDBA或者SYSOPER. 2.关闭数据库的工具:SQL* PLUS或者SRVCTL. 3.关闭数据库的四种模式:normal(sql * plus工具默认),immed ...

  7. Oracle开启和关闭的几种模式

    目录 1 启动数据库 1.1 nomount模式 1.2 mount模式 1.3 open模式 1.4 force模式 2 关闭数据库 2.1 normal方式 2.2 transactional方式 ...

  8. Linux中的SELinux详解--16

    SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled)  几种模式之间的转换 在CentOS6.2 中安装intel 的c++和fortran 的编 ...

  9. linux必须运行在enforcing,Linux系统中SELinux的工作模式(Disabled、Permissive和Enforcing)...

    通过对SElinux的介绍,初学者可以这样认为,在传统Linux系统使用访问控制方式的基础上,附加使用SELinux可增强系统安全.那么,SELinux是如何运行的呢? 在解释 SELinux 的工作 ...

最新文章

  1. dac0832控制电机驱动流程图_智能电机驱动器让你的机器人控制更简单
  2. 退役笔记一#MySQL = lambda sql : sql + #39; Source Code 4 Explain Plan #39;
  3. python date time
  4. 死锁产生的4个必要条件,如何检测,解除死锁
  5. 统计学---数据的标准化
  6. 高性能的序列化与反序列化:kryo的简单使用
  7. [HNOI2003]操作系统
  8. 中间件是什么?在.NET Core中的工作原理又是怎样的呢?
  9. 怎样在 Centos 6.8 中安装 Elasticsearch 5.2
  10. CPPUnit 测试宏
  11. 随想录(反调试技术)
  12. Rust 1.34.0 发布
  13. 15寸计算机显示器,苹果确认15寸RMBP支持全球首款5K显示器
  14. [POI2009]石子游戏Kam
  15. python方向是干什么的_Python有哪些应用方向 在数据分析上有什么优势
  16. DBSCAN聚类算法详解
  17. 虹科分享 | 基于流的流量分类的工作原理 | 网络流量监控
  18. scrapy_redis实现分布式爬取京东图书数据
  19. DxO PhotoLab 4 for Mac(RAW图片处理工具)
  20. 教程丨利用微软官方工具制作U盘安装Win10系统

热门文章

  1. 抛出错误_不用try catch,如何机智的捕获错误
  2. 匈牙利算法——最大匹配问题详解
  3. mysql自带的卸数工具_数据库卸数必备工具下载-数据库数据导出工具(DBexport)下载v1.3官方版-西西软件下载...
  4. 华为鸿蒙os2.0系统何时搭载手机,鸿蒙OS 2.0系统正式发布!余承东:明年华为系手机将会搭载...
  5. 绳索受力分析的软件_【硕士论文】供热管网管道支架载荷分析与优化设计
  6. html页面左右布局透明背景,HTML透明背景
  7. mysql 主从备份问题_我遇到的mysql主从同步的问题
  8. 深度技术win11 64位正版系统v2021.07
  9. win7纯净版镜像系统安装教程
  10. ECharts 联动效果