Redhat(2)-SELINUX-基本操作

1.SELINUX基本操作
2.排除故障


1.SELINUX基本操作
防止已遭泄漏的系统服务访问用户数据。
问题:
用户:ugo===r  有读取的权限,但用什么工具不确定。
文件:file,支持什么工具看?
selinunx 可以控制进程是否访问。
httpd以apache运行,取决于当前运行的用户;
apache 无/temp访问权限,但是httpd访问了/temp,这是不对的。
1.1查看文件标签  可以查到是什么执行程序访问这个文件。

#查看文件标签  可以查到是什么执行程序访问这个文件
ls -Z /sbin/httpd  /tmp -d1
system_u:object_r:httpd_exec_t:s0 /sbin/httpd
#  用户:  角色:    执行程序 setype

1.2查看服务的标签,服务和标签不一定是一样的。

#1.启动服务
systemctl start httpd
pgrep httpd
#2.查看有httpd标签的文件 
ps -Z $(pgrep httpd)

1.3 cp文件,权限取决于目标目录。

cp -Z index2.html /var/www/html/index3.html # dest目标目录的权限
cp -a index2.html /var/www/html/index4.html # 保留原文件权限

1.4 mv文件,保留原有文件权限

mv  index2.html /var/www/html/index5.html    # 保留原文件权限
mv -Z index2.html /var/www/html/index6.html  # 保留目标文件权限

1.5启动

#确保selinux是启动的
#查看+修改配置文件+重启
getenforce

vim  /etc/selinux/config
SELINUX=enforcing

reboot

1.6更改文件标签

ls -Z f1
chcon -t samba_share_t f1

1.7恢复文件标签

restorecon f1 -V

1.9添加类型更改标签

#1.添加标签类型
semanage fcontext -a -t samba_share_t  '/samba(/.*)?'
#2.重新打标签
restorecon -Rv /samba/


semanage fcontext -l|grep ^/root

1.10 对文件的操作

#1.删掉原有文件夹内容 后写文件
cd /var/www/html/
rm * -f  

#2.启动服务器
systemctl status httpd
systemctl start httpd

#3.在/var/www/html/添加文件   可以访问
cd  /var/www/html/
echo hello world >index.html
curl http://servera.lab.example.com

cd 在家目录下添加文件        不可以访问
echo error > error.txt
mv error.txt /var/www/html/
ll /var/www/html/error/txt
ls -Z /var/www/html/error.txt

#4.想访问2种方式
#4.1 
setenforce 0
$4.2 重新赋权
setenforce 1
restorecon -Rv /var/www/html/

1.11对端口的操作

semanage port -l|grep http
semanage port -l|grep -e http -i -e pro
    
#查看80端口被谁访问 httpd
#修改httpd.conf
#无法重启
lsof -i :80 
vim /etc/httpd/conf/httpd.conf
systemctl restart httpd          #无法重启
systemctl status httpd.service|cat

#1.关了后就可以启动了
setenforce 0
systemctl restart httpd

#2.添加端口后就可以了
semanage port -a -p tcp -t http_port_t 10080
systemctl restart httpd

#3.删掉+改conf
semanage port -d -p tcp -t http_port_t 10080
vim /etc/httpd/conf/httpd.conf
systemctl restart httpd

1.12 BOOL
 更改selinux策略行为的开关,可以启动和禁用
 

#查看SELinux
getsebool -a
getsebool samba_export_all_ro  samba_export_all_rw

#设置SELinux
setsebool samba_export_all_ro=1
setsebool -P samba_export_all_ro=1
setsebool samba_export_all_ro=1 samba_export_all_rw=1


~
semanage boolean -l||head
#查看文件
man --k _selinux
#查找包
yum list selinux*poli*doc*
selinux-policy-doc

yum install -y selinux-policy-doc
man -k httpd_selinux

# student 下创建目录  想让apache用户访问
# 主页位置指向  修改配置文件vim /etc/httpd/conf/httpd.conf
mkdir html
cd html/
chmod 755 student/
vim /etc/httpd/conf/httpd.conf
#DocumentRoot "/var/www/html"
DocumentRoot "/home/student/html"

2.排除故障
2.1是否是selinux引起的
    setenforce 0
2.2是不是正确的上下文
    restorecon
2.3是不是正确的Bool值
2.4端口是否正确


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值