0.基础知识准备:首先我们需要知道在selinux没有启用的状态下,系统执行的是DAC即自主访问控制,同时我们还需要知道MAC即强制访问控制的概念。
1.cat /etc/selinux/config查看selinux的配置文件,这里可以看到enforcing(非授权访问会受限制) permissive(非授权访问不会受限制,但会在审计日志中进行记录) disabled(关闭)三种可选择的状态。selinux是运行在内核层面的,从disabled变为enforcing的时候,系统会从内核对文件的安全上下文进行重启标记。
[root@lab1 ~]# cat /etc/selinux/config
# 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
2. ll -Z这里通过-Z参数可以看到selinux的安全上下文。这里采用的是用户:角色:类型:层级的标记方法,需要了解的主要是前三项,其中用户是指selinux的用户,需要区别于系统里创建的用户。
[root@lab1 ~]# ll -Z
-rw-------. root root system_u:object_r:admin_home_t:s0 anaconda-ks.cfg
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 linux-3.16.61.tar.xz
-rw-------. root root unconfined_u:object_r:admin_home_t:s0 my-ks.cfg
3.getsebool -a | head -n10查看selinux相关的功能,并查看其功能的状态是否开启。
[root@lab1 ~]# getsebool -a | head -n10
abrt_anon_write --> off
abrt_handle_event --> off
abrt_upload_watch_anon_write --> on
antivirus_can_scan_system --> off
antivirus_use_jit --> off
auditadm_exec_content --> on
authlogin_nsswitch_use_ldap --> off
authlogin_radius --> off
authlogin_yubikey --> off
awstats_purge_apache_log_files --> off
4.getenforce可以查看selinux当前的状态。setenforce 0修改selinux当前的状态。getenforce重新查看发现状态已经改变。如果要关闭selinux,前面已经讲过,需要去改配置文件。
[root@lab1 ~]# getenforce
Enforcing
[root@lab1 ~]# setenforce 0