linux之selinux强制访问控制

selinux

selinux是强制访问控制的一种策略,可以指明某一个进程访问哪些资源,在传统的linux中,一切皆文件,由用户、组和权限来控制访问,在selinux中,一切皆对象,由存放在扩展属性领域的安全元素控制访问,所有文件、端口、进程都具备安全上下文
selinux影响着:(1)程序访问文件(2)程序访问功能(微信),进程本身功能,开关

查询selinux状态

命令:getenforce #查询结果有3种状态
1、enforcing #如果违反了策略,无法继续操作,表示强制
2、disabled #禁止
3、permissive #selinux有效,即是违法策略,依旧可以继续操作,但是会有警告,查看警告信息:cat /var/log/audit/audit.log

更改selinux状态

vim /etc/sysconfig/selinux #文件编辑
reboot #重启
测试:

[root@localhost ~]# getenforce
Disabled
[root@localhost ~]#vim /etc/sysconfig/selinux  #修改selinux=Enforcing
[root@localhost ~]#reboot  #重启
[root@localhost ~]# getenforce  
Enforcing

临时改变selinux状态

setenforce 0 | 1 #临时改变selinux状态,其中0表示警告模式;1表示强制模式
getenforce 查看状态
查询结果:
Permissive #警告模式,警告不被拒绝
Enforcing #强制模式,拒绝并且警告
测试:

[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# setenforce 1
[root@localhost ~]# getenforce
Enforcing

selinux安全上下文管理

selinux之安全上下文介绍:https://blog.csdn.net/Ying_smile/article/details/109050734

做selinux安全上下文时首先需要开启vsftpd,关闭firewalld

[root@localhost ~]# systemctl restart vsftpd
[root@localhost ~]# systemctl enable vsftpd
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'

1.安全上下文

ls -Z #查看文件的安全上下文
semanage fcontext -l #内核指定的所有文件的安全上下文的列表 ; 查看文件安全上下文(man semanage fcontext)
测试:

服务端:
[root@localhost ~]# touch /mnt/haha1
[root@localhost ~]# mv /mnt/haha1 /var/ftp/haha1  #复制是新建的过程,移动是重命名的过程,文件系统权限和属性不会改变
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# cd /var/ftp
[root@localhost ftp]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:mnt_t:s0   haha1  #安全上下文为mnt_t
-rw-r--r--. root root system_u:object_r:public_content_t:s0 hellohello  #安全上下文为public_content_t
drwxr-xr-x. root root system_u:object_r:public_content_t:s0 pub
[root@localhost ftp]# semanage fcontext -l | grep /var/ftp  #内核记录的/var/ftp的安全上下文
/var/ftp(/.*)?                                     all files          system_u:object_r:public_content_t:s0 
/var/ftp/bin(/.*)?                                 all files          system_u:object_r:bin_t:s0 
/var/ftp/etc(/.*)?                                 all files          system_u:object
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值