Linux【9】-进程管理4-2-2--安全模块--安装与查看和关闭SELinux

一、安装

在 CentOS 6.x 中,SELinux 也是整合到 Linux 的内核当中的,并且是启动的,所以不需要单独安装。不过,现在不再像在 CentOS 5.x 中,所有的 SELinux 工具都是已经安装和配置好的,在 CentOS 6.x 中,虽然 SELinux 的主程序默认已经安装,但是很多的 SELinux 管理工具需要我们手工安装。

SELinux 安装命令如下:

[root@localhost ~]# yum -y install setroubleshoot
[root@localhost ~]# yum -y install setools-console

这两条命令要想正确运行,需要搭建正确的 yum 源。这两个软件包在安装时会依赖安装一系列的软件包,这些软件包中包含了 SELinux 的常用工具。

通过以上的介绍,读者应该对 SELinux 有了初步的认识,下面我们再通过了解 SELinux 的工作模式,细致了解 SELinux。

二、 查看SELinux状态

2.1 getenforce

  • getenforce 命令是单词get(获取)和enforce(执行)连写,可查看selinux状态,与setenforce命令相反。
  • setenforce 命令则是单词set(设置)和enforce(执行)连写,用于设置selinux防火墙状态,如: setenforce 0用于关闭selinux防火墙,但重启后失效

例子:

[root@localhost ~]# getenforce
Enforcing

2.2 /usr/sbin/sestatus

Current mode表示当前selinux防火墙的安全策略

[root@localhost ~]# /usr/sbin/sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

其中:

  • SELinux status:selinux防火墙的状态,enabled表示启用selinux防火墙
  • Current mode: selinux防火墙当前的安全策略,enforcing 表示强

三. 关闭SELinux

3.1 临时关闭

setenforce 0 :用于关闭selinux防火墙,但重启后失效。

[root@localhost ~]# setenforce 0
[root@localhost ~]# /usr/sbin/sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

3.2 永久关闭

修改selinux的配置文件,重启后生效。

打开 selinux 配置文件

[root@localhost ~]# vim /etc/selinux/config

修改 selinux 配置文件

将SELINUX=enforcing改为SELINUX=disabled,保存后退出

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

此时获取当前selinux防火墙的安全策略仍为Enforcing,配置文件并未生效。

[root@localhost ~]# getenforce
Enforcing
重启
[root@localhost ~]# reboot
验证
[root@localhost ~]# /usr/sbin/sestatus
SELinux status:                 disabled

[root@localhost ~]# getenforce
Disabled
药企,独角兽,苏州。团队长期招人,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn