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 roroot=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<sl May07   0:01 auditd

system_u:system_r:auditd_t      root     4024  0.0  0.4 13072   628 ?        S<sl May07   0:00 /sbin/a

system_u:system_r:restorecond_troot      4040  0.0 4.4  10284  5556 ?       Ss   May07  0:00 /usr/sb

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

selinux 的使用的更多相关文章

  1. 关闭selinux

    1.查看SELinux状态:getenforce Enforcing(启动) disable(禁用) 1.禁用SELinux(重启后依然生效) 修改 vi /etc/sysconfig/selinux ...

  2. 关闭SELinux和iptables防火墙

    1.关闭SELinux: 编辑SELinux配置文件: [root@Redis selinux]# vim /etc/selinux/config 修改SELINUX配置项为disable SELIN ...

  3. 开发thinkphp的第一步就是给Application目录(不包括其下的文件)777权限, 关闭selinux

    开发thinkphp的时候, 总是会出现各种个样 的奇怪的毛病, 比如: 说什么Application目录不可写, 比如: 说什么 _STORAGE_WRITE_ERROR, 不能生成 Runtime ...

  4. linux系统的初化始配置(包括网络,主机名,关闭firewalld与selinux)

    每次我们使用Linux都会对系统进行初始化的配置,下面我们一一列出来. 1.服务的开启 systemctl enable firewalld.service //将指定的服务设置为开机启动 syste ...

  5. SElinux对一些服务关系的影响

    kerberos 允许系统使用kerberos  setsebool -P allow_kerberos 1 setsebool -P krb5kdc_disable_trans 1 service ...

  6. Centos 7 安装 设置 IP地址,DNS,主机名,防火墙,端口,SELinux (实测+笔记)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.虚拟系统安装 1.1 使 ...

  7. Linux下开启关闭SeLinux

    SELinux (Security-Enhanced Linux) in Fedora is an implementation of mandatory access control in the ...

  8. 关闭Linux防火墙(iptables) 及 SELinux

    一.关闭防火墙 1.重启后永久性生效: 开启:chkconfig iptables on 关闭:chkconfig iptables off 2.即时生效,重启后失效: 开启:service ipta ...

  9. selinux 导致无法启动httpd

    selinux 导致无法启动httpd ansible_dire:~ # /etc/init.d/httpd restart 停止 httpd: [失败]正在启动 httpd:(13)Permissi ...

  10. Linux selinux iptables

    关闭SELINUX – 使用getenforce命令检查SELINUX状态,若结果不是”Disabled”,可使用setenforce 0命令临时关闭SELINUX.要永久关闭SELINUX,需修改/ ...

随机推荐

  1. 【理论】X理论、Y理论及Z理论

      道格拉斯·麦格雷戈(Douglas Mcgregor)把对人的基本假设作了区分,即X理论和Y理论.X理论认为:人们总是尽可能地逃避工作,不愿意承担责任,因此要想有效地进行管理,实现组织的目标,就必 ...

  2. How to hosts

    sudo cp /etc/hosts /etc/hosts.bak sudo cp ~/Desktop/hosts /etc/hosts sudo systemctl restart NetworkM ...

  3. 源码分析: 图片加载框架Picasso源码分析

    使用: Picasso.with(this) .load("http://imgstore.cdn.sogou.com/app/a/100540002/467502.jpg") . ...

  4. BZOJ4032[HEOI2015]最短不公共子串——序列自动机+后缀自动机+DP+贪心

    题目描述 在虐各种最长公共子串.子序列的题虐的不耐烦了之后,你决定反其道而行之. 一个串的“子串”指的是它的连续的一段,例如bcd是abcdef的子串,但bde不是. 一个串的“子序列”指的是它的可以 ...

  5. 洛谷P1092 虫食算(算竞进阶习题)

    模拟+dfs 这个题就三行,搜索的话我们从右向左,从上到下.. 如果是在1,2行我们就直接枚举0-n所有数,但是到了第三行,最直接的就是填上这一列上前两行的数的和modN,在此基础上判断该填的数有没有 ...

  6. [USACO18DEC]Balance Beam

    题目链接:这里 或者这里 答案是很显然的,记\(g(i)\)为在\(i\)下平衡木时的期望收益 那么\(g(i)=max(f(i),\frac{g(i-1)+g(i+1)}{2})\) 好了做完了 T ...

  7. github 快速部署

    在github上 新建一个项目后,并且未提交任何代码,会有一个页面提示我们如何快速部署.在此备份一下那个页面 Quick setup — if you’ve done this kind of thi ...

  8. 对如下字符串(234453)[234]{2324}分析它的括号使用是否正确,括号匹配(Java实现)

    我的一种思路是递归: private static String s = "(2344[)]53[234]{2324}"; private static boolean f(int ...

  9. day5 笔记

    笔记 字符格式化输出: 占位符%s s=string 字符型%d d=dight 整数型%f f=float 浮点数 约等于小数 通过格式:%(str1,str2,str3)一一对应 数据运算 数据类 ...

  10. 使用 Zabbix 监控 Jenkins

    笔者最近的工作涉及到使用 Zabbix 监控 Jenkins.在谷歌上搜索到的文章非常少,能操作的就更少了.所以决定写一篇文章介绍如何使用 Zabbix 监控 Jenkins. 下图为整体架构图: 整 ...