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:


[root@localhost ~]# seinfo -a     #查看上下文件的控制类型

 4.修改文件类型:

4.1查看httpd进程:

[root@localhost html]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
[root@localhost html]# 
[root@localhost html]# ps auxZ|grep httpd ###过滤httpd进程
system_u:system_r:httpd_t:s0    root      51859  0.0  0.2 221952  4996 ?        Ss   13:50   0:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache    51860  0.0  0.1 224036  3104 ?        S    13:50   0:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache    51861  0.0  0.1 224036  3104 ?        S    13:50   0:00 /usr/sbin/httpd -DFOREGROUND

4.2.用7-1curl访问7-2:

4.3.在7-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.4.开一下selinux:

4.5.用7-1再去访问index.html页面:

报错了

4.6.把selinux关掉:

又可以了 

5.去7-3改端口:

1.先把selinux开启:

2.去主配置文件中加端口: 

3.解决进程与端口绑定问题

6.selinux的配置文件:

[root@localhost html]# vim /etc/selinux/config

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值