linux安全管理教程,Linux基础教程学习笔记22——管理SELinux安全

Linux基础教程学习笔记22——管理SELinux安全

一、ugo模式主动访问控制DAC

文件的权限控制ugo  rwx

二、selinux强制访问控制MAC

每个文件资源都有一个标记,特定标记的进程,只能访问特定标记的资源,无法访问其他资源,即使资源的权限设置为777(rwx)

三、查看和设置文件和进程的安全标记

使用-Z的选项可以查看文件和进程的标记,以httpd服务为例子:

[root@linuxidc tmp]# ls -Z

--wx-----x. root  root  unconfined_u:object_r:user_tmp_t:s0 a1

-----w----. root  root  unconfined_u:object_r:user_tmp_t:s0 a4

---------x. root  root  unconfined_u:object_r:user_tmp_t:s0 a5

[root@linuxidc html]# ps auxZ|grep httpd

system_u:system_r:httpd_t:s0    root      5477  0.1  0.4 213692  4904 ?        Ss

[root@linuxidc html]# ls -ldZ /var/www/html/

drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/

在根下创建一个www的目录,并在/var/www/html下面做一个www的软链接:

[root@linuxidc html]# mkdir /www

[root@linuxidc html]# ln -s /www/ www

[root@linuxidc html]# ls

index.html  iso  ks.cfg  www

/www目录的默认的上上下文为,没有标记为httpd:

[root@linuxidc html]# ls -ldZ /www/

drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /www/

如果这时候启动httpd服务,打开浏览器,访问www目录,会提示不被允许:

8ce2cb4c4c902b9272d4b9e2f9a9a0db.png

修改/www目录的上下文,使其上下文与/var/www/html一致,再打开www目录即可访问:

[root@linuxidc html]# chcon -R --reference=/var/www/html/ /www

[root@linuxidc html]# ls -ldZ /www/

drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /www/

abebea75f1e69e294f91958cd560cc82.png

使用restorecon命令可以恢复文件资源的默认上下文:

[root@linuxidc html]# ls -ldZ /www/

drwxr-xr-x. root root system_u:object_r:default_t:s0  /www/

使用chcon命令只能临时改变文件资源的上下文,重启电脑则会恢复默认值,要想永久的修改默认的上下文,则需使用semanage命令:

[root@linuxidc html]# semanage fcontext -a -t httpd_sys_content_t '/www(/.*)?'

使用restorcon命令再恢复默认上下文,则恢复的是最新设置的上下文

使用-d选项可以删除默认的上下文:

[root@linuxidc html]# semanage fcontext -d -t httpd_sys_content_t '/www(/.*)?'

四、selinux的三种模式

1、enforcing

使用getenforce可以查看系统当前的模式:

[root@linuxidc html]# getenforce

Enforcing

不符合selinux模式则会报警,同时会阻止相关的操作

2、permissive

切换到permissive模式,使用setenforce

[root@linuxidc html]# setenforce 0

[root@linuxidc html]# getenforce

Permissive

不符合selinux模式的操作,permissive会有警报,但是不会阻止相关的操作;

3、disable

在/etc/selinux/config文件中可永久修改selinux模式:

五、修改selinux模式的布尔值

使用getsebool -a命令查看所有的布尔值

[root@linuxidc html]# getsebool -a

abrt_anon_write --> off

abrt_handle_event --> off

abrt_upload_watch_anon_write --> on

如果搭建了某个服务,在客户端访问该服务,写不进任何东西,可以按以下步骤检查:

1、检查配置文件是否开启了相关的写权限;

2、文件系统权限

3、selinux上下文和布尔值是否开启了相关的权限

图形化管理selinux可以安装相关的包,使用system-config-selinux命令;

0b1331709591d260c1c78e86d0c51c18.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值