[root@kvm8 ~]# ll /var/www/html/ total 12 -rw-r--r--. 1 root root 10 Sep 27 17:10 file1 -rw-r--r--. 1 root root 10 Sep 27 17:10 file2 -rw-r--r--. 1 root root 10 Sep 27 17:10 file3
[root@kvm8 ~]# curl http://localhost:82/file1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access this resource.</p> </body></html> [root@kvm8 ~]# curl http://localhost:82/file2 web test2 [root@kvm8 ~]# curl http://localhost:82/file3 web test3
admin_home_t,而 file2 及 file3 是 httpd_sys_content_t,所以 SELinux 策略不允許 httpd 存取 file1。
[root@kvm8 ~]# ll -Z /var/www/html/ total 12 -rw-r--r--. 1 root root system_u:object_r:admin_home_t:s0 10 Sep 27 17:10 file1 -rw-r--r--. 1 root root system_u:object_r:httpd_sys_content_t:s0 10 Sep 27 17:10 file2 -rw-r--r--. 1 root root system_u:object_r:httpd_sys_content_t:s0 10 Sep 27 17:10 file3
[root@kvm8 ~]# restorecon -v /var/www/html/file1
[root@kvm8 ~]# ll -Z /var/www/html/ total 12 -rw-r--r--. 1 root root system_u:object_r:admin_home_t:s0 10 Sep 27 17:10 file1 -rw-r--r--. 1 root root system_u:object_r:httpd_sys_content_t:s0 10 Sep 27 17:10 file2 -rw-r--r--. 1 root root system_u:object_r:httpd_sys_content_t:s0 10 Sep 27 17:10 file3
admin_home_t,所以還原時不會變動。
[root@kvm8 ~]# semanage fcontext --list | grep file1 /var/www/html/file1 all files system_u:object_r:admin_home_t:s0
[root@kvm8 ~]# semanage fcontext --delete --type admin_home_t /var/www/html/file1
[root@kvm8 ~]# semanage fcontext --list | grep file1
[root@kvm8 ~]# restorecon -v /var/www/html/file1 Relabeled /var/www/html/file1 from system_u:object_r:admin_home_t:s0 to system_u:object_r:httpd_sys_content_t:s0 [root@kvm8 ~]# curl http://localhost:82/file1 web test1
httpd_sys_content_t。
[root@kvm8 ~]# ll -Z /var/www/html/ total 12 -rw-r--r--. 1 root root system_u:object_r:httpd_sys_content_t:s0 10 Sep 27 17:10 file1 -rw-r--r--. 1 root root system_u:object_r:httpd_sys_content_t:s0 10 Sep 27 17:10 file2 -rw-r--r--. 1 root root system_u:object_r:httpd_sys_content_t:s0 10 Sep 27 17:10 file3
[root@kvm8 ~]# curl http://localhost:82/file1 web test1