系统运维-14-3-Selinux基础知识

本文介绍了Selinux的基础知识,包括自主访问控制与强制访问控制的区别,以及Selinux的三种工作模式。详细讲解了如何查看和修改Selinux状态,通过ll -Z观察文件的安全上下文,以及使用chcon修改文件上下文。此外,还涉及到通过getsebool调整Selinux策略,以及在Web服务中遇到的权限问题和解决方法,最后提到了审计日志的查看。
摘要由CSDN通过智能技术生成

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

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值