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]#