SElinux 规则

1. 查看selinux状态

SELinux的状态:

  • enforcing:强制,每个受限的进程都必然受限
  • permissive:允许,每个受限的进程违规操作不会被禁止,但会被记录于审计日志
  • disabled:禁用

相关命令:

  • getenforce :获取selinux当前状态
  • sestatus :查看selinux状态
  • setenforce 0 | 1    
  • 0 设置为 permissive  宽容模式
  • 1 设置为 enforcing 强制
[root@localhost html]#getenforce 
Enforcing
 
 
如果没有开启可以使用以下命令开启
[root@localhost html]#setenforce 1
 
 
永久开启需要修改  此处文件  /etc/selinux/config
vim /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

配置文件

2. 文件类型 

3. seinfo

yum provides seinfo #查看包的来源
yum install setools-console.x86_64 -y    #安装
seinfo -a     #查看上下文件的控制类型

4. 查看文件类型

4.1 查看httpd进程

cd /var/www/html
ls -Z

访问测试

可以看到 那是因为这个模块 httpd_sys_content_t

4.2 修改文件类型

[root@localhost html]# chcon -t var_t /var/www/html/index.html
[root@localhost html]# 
[root@localhost html]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:var_t:s0   index.html
[root@localhost html]# 

此时访问不到了

4.3 控制端口

vim /etc/httpd/conf/httpd.conf

systemctl restart httpd

问题解决:

[root@localhost html]# semanage port -a -t http_port_t -p tcp 9527
[root@localhost html]# 
[root@localhost html]# systemctl restart httpd
[root@localhost html]# 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值