chcon和semanage fcontext的坑

本文探讨了在使用chcon命令更改文件上下文后,如何避免默认上下文丢失及samba_share_t权限问题,强调了正确使用semanage fcontext与restorecon的重要性。

 chcon后不能restorecon,不然就default_t:s0,samba_share_t没了

chcon ======================semanage fcontext  +  restorecon

 

 

Selinux 原理介绍 自主访问控制 传统 Linux discretionary access control, DAC) 强制访问控制 MAC SELinux 的策略类型:Targeted 默认策略 8. Selinux 的使用 ID SEC OPERATION SELinux 1 filesystem chmod, chown, setfacl, chattr guestfish (selinux-relabel) virt-custmize (--selinux-relabel) touch /.autorelabel 2 service vim /etc/ssh/sshd_config setsebool getsebool 3 firewall iptables, firewalld semanage port ... 4 Selinux vim /etc/selinux/config 1. 上下文关系 guestfish ><fs> selinux-relabel /etc/selinux/targeted/contexts/files/file_contexts / virt-custmize virt-customize \ --selinux-relabel \ ... 8.6.3. 重置 root 密码 # touch /.autorelabel # sync apache yum -y install httpd rpm -qc httpd vim /etc/httpd/conf/httpd.conf echo Hello world > /var/www/html/index.html ls -lZ /var/www/html/index.html ls -ldZ /var/www/html ls -ldZ /var/www ls -ldZ /var systemctl enable --now httpd curl localhost firewall-cmd --permanent --add-service=http firewall-cmd --reload mkdir /srv/www grep /var/www/html /etc/httpd/conf/httpd.conf sed -i 's+/var/www/html+/srv/www+' /etc/httpd/conf/httpd.conf grep /srv/www /etc/httpd/conf/httpd.conf echo Hello huhehaote > /srv/www/index.html systemctl restart httpd curl localhost setenforce 0 curl localhost setenforce 1 curl localhost A # yum search selinux # yum -y install selinux-policy-doc.noarch # mandb # man -k selinux # man httpd_selinux B # yum provides *sealert # yum -y install setroubleshoot-server # sealert -a /var/log/audit/audit.log # semanage fcontext -a -t FILE_TYPE '/srv/www/index.html' # restorecon -v '/srv/www/index.html' C # man semanage fcontext | grep \# # semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?" # restorecon -R -v /web HTTPD_DIR=/srv/www semanage fcontext -a -t httpd_sys_content_t "/${HTTPD_DIR}(/.*)?" restorecon -R -v ${HTTPD_DIR} ls -ldZ /srv/www/{.,*} curl localhost
09-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值