SELinux的状态:
- enforcing:强制,每个受限的进程都必然受限
- permissive:允许,每个受限的进程违规操作不会被禁止,但会被记录于审计日志
- disabled:禁用
相关命令:
[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

- [root@localhost ~]# seinfo -t
- bash: seinfo: 未找到命令...
- [root@localhost ~]# yum provides seinfo
- 已加载插件:fastestmirror, langpacks
- Loading mirror speeds from cached hostfile
- * base: mirrors.bfsu.edu.cn
- * extras: mirrors.bfsu.edu.cn
- * updates: mirrors.bfsu.edu.cn
- extras/7/x86_64/filelists_db | 303 kB 00:00:00
- setools-console-3.3.8-4.el7.x86_64 : Policy analysis command-line tools for SELinux
- 源 :base
- 匹配来源:
- 文件名 :/usr/bin/seinfo

[root@localhost ~]# yum install setools-console-3.3.8-4.el7.x86_64 -y

- [root@localhost ~]# seinfo -a
-
- Attributes: 256
- cert_type
- privfd
- file_type
- boinc_domain
- cfengine_domain
- wine_domain

- [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


- [root@localhost html]# ls
- index.html
- [root@localhost html]#
- [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]# 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]#

- [root@localhost html]# getenforce
- Permissive
- [root@localhost html]# setenforce 1
- [root@localhost html]# getenforce
- Enforcing
- [root@localhost html]#


[root@localhost html]# setenforce 0

- [root@localhost ~]# curl 192.168.91.102
- 7-2

- [root@localhost html]# setenforce 1
- [root@localhost html]# getenforce
- Enforcing
- [root@localhost html]#


- [root@localhost html]# vim /etc/httpd/conf/httpd.conf
- [root@localhost html]#
- [root@localhost html]# systemctl restart httpd
- Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
- [root@localhost html]#

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

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