[root@localhost ~]# chcon [選項] 文件或目錄
選項:[root@localhost ~]# echo'test page!??!' >> /var/www/html/index.html
#建立一個網(wǎng)頁文件,并寫入“test page?。。?rdquo;

[root@localhost ~]# ls -Z /var/www/html/index.html
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html
#這個網(wǎng)頁文件的模式類別是httpd_sys_content_t
[root@localhost ~]# seinfo -t I grep var_t
#查詢SELinun中所有的類型、發(fā)現(xiàn)有一個類型叫var_t
[root@localhost ~]# chcon -t var_t /var/www/html/index.html
#把網(wǎng)頁文件的類型修改為var_t類型
[root@localhost ~]# ls -Z /var/www/html/index.html
-rw-r--r--. toot root unconfined_u:object_r:var_t:s0 /var/www/html/index.html
#這個網(wǎng)頁的類型已經(jīng)被修改了

[root@localhost ~] # restorecon [選項】 文件或目錄
選項:[root@1ocalhost ~]# restorecon -Rv /var/www/html/index.html
restorecon  reset   /var/www/html/index.html    context
unconfined_u:object_r:var_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
#這里已經(jīng)提示了安全上下文從var_t恢復(fù)成了httpd_sys_content_t
[root@1ocalhost ~]# ls -Z /var/www/html/index.html
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html
#查看一下,安全上下文已經(jīng)恢復(fù)正常了.網(wǎng)頁的訪問也已經(jīng)恢復(fù)正常了
新聞熱點
疑難解答
圖片精選