SELinux的启动和关闭

1、SELinux简介

SELinux是Security Enhanced Linux的缩写,字面上的意思就是安全强化的Linux,它是由美国国家安全局 (NSA) 开发的,整合到Linux核心的一个模块,是对于强制访问控制(MAC)的实现,是 Linux历史上最杰出的新安全子系统,提供了比传统的UNIX权限更好的访问控制。在SELinux的访问控制体系的限制下,进程只能访问那些在他的任务中所需要文件。

2、SELinux 的启动、关闭和状态

并非所有的 Linux发行版都支持 SELinux 的,CentOS 5.x 以后就支持 SELinux了,目前 SELinux 支持三种模式:

  • enforcing:强制模式,表示SELinux 运行中,且已经正确的开始限制 domain/type 了;
  • permissive:宽容模式,表示SELinux 运行中,不过仅会有警告信息,并不会实际限制 domain/type 的存取。这种模式可以运来作为 SELinux 的 debug 之用;
  • disabled:关闭,SELinux 没有运行。
1)获取SELinux的状态

[root@www ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted

2)获取SELinux运行模式

[root@www ~]# getenforce
Enforcing //当前的模式为 Enforcing

3)SELinux运行模式切换

[root@www ~]# setenforce [0|1]
选项与参数:
0:转成 Permissive 宽容模式;
1:转成 Enforcing 强制模式

[root@www ~]# setenforce 0
[root@www ~]# getenforce
Permissive

[root@www ~]# setenforce 1
[root@www ~]# getenforce
Enforcing

4)SELinux 的启动和关闭

由于SELinux 整合到Linux核心里了,如果由 enforcing 或 permissive模式改成 disabled,或由 disabled 改成其他两个,系统必须要重新启动;
在 SELinux运行(enforcing或permissive模式)时,只能在enforcing和permissive模式切换,不能够直接关闭 SELinux,只能通过修改配置文件,然后重启系统。
在 SELinux关闭(disabled)时,setenforce命令不能设置Enforcing或Permissive模式,只能通过修改配置文件来设置,然后重启系统。

[root@www ~]# vim /etc/selinux/config
SELINUX=enforcing                //默认为enforcing,可设置为enforcing、permissive、disabled中的一项。
SELINUXTYPE=targeted //目前只能设置成targeted、mls中的一项

注意:
1)如果从 disable 切换到enforcing或permissive模式时,由于系统必须要针对文档写入安全性本文的信息,因此开机过程会花费不少时间在等待重新写入 SELinux 安全性本文 (有时也称为 SELinux Label),而且在写完之后还得要再次的重新启动。
2)如果已经运行在Enforcing模式,但是可能由于SELinux的设置问题,导致某些服务无法正常的运行,此时可以将Enforcing 模式改为Permissive模式,让 SELinux只会警告无法顺利联机的信息,而不是直接阻挡主体程序的读取权限。

3、SELinux布尔变量

SELinux的一些布尔变量的设置对程序的运行起着控制作用,有时需要根据情况需要打开或关闭。
[root@www ~]# getsebool -a | grep samba //获取和samba安全性设置有关的布尔值
bacula_use_samba --> off
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
use_samba_home_dirs --> off
virt_use_samba --> off

[root@www ~]#setsebool -P samba_enable_home_dirs=1

[root@www ~]# getsebool samba_enable_home_dirs
samba_enable_home_dirs --> on

4、SELinux安全性文本

1)查看文件的安全性文本
[root@localhost home]# ls -Z rjfws/     
drwxrws---. rjfws rjfws unconfined_u:object_r:user_home_t:s0 data
drwxr-xr-x. rjfws rjfws unconfined_u:object_r:user_home_t:s0 公共的
drwxr-xr-x. rjfws rjfws unconfined_u:object_r:user_home_t:s0 模板
drwxr-xr-x. rjfws rjfws unconfined_u:object_r:user_home_t:s0 视频
drwxr-xr-x. rjfws rjfws unconfined_u:object_r:user_home_t:s0 图片
drwxr-xr-x. rjfws rjfws unconfined_u:object_r:user_home_t:s0 文档
drwxr-xr-x. rjfws rjfws unconfined_u:object_r:user_home_t:s0 下载
drwxr-xr-x. rjfws rjfws unconfined_u:object_r:user_home_t:s0 音乐
drwxr-xr-x. rjfws rjfws unconfined_u:object_r:user_home_t:s0 桌面

2)查看目录的安全性文本
[root@localhost home]# ls -Zd rjfws/   
drwxrwx---. rjfws rjfws unconfined_u:object_r:user_home_dir_t:s0 rjfws/

=-=-=-=-=
Powered by Blogilo

posted on 2017-10-03 23:13  chenxiaopang  阅读(19046)  评论(0编辑  收藏  举报

导航