Using restorecon

Using restorecon is easy. Just type restorecon, followed by the name of the file that you need to change. Once again, I've changed the context of the index.html file back to the home directory type. This time though, I'm using restorecon to set the correct type:

[donnie@localhost html]$ ls -Z
-rw-rw-r--. donnie donnie unconfined_u:object_r:user_home_t:s0 index.html

[donnie@localhost html]$ sudo restorecon index.html

[donnie@localhost html]$ ls -Z
-rw-rw-r--. donnie donnie unconfined_u:object_r:httpd_sys_content_t:s0 index.html
[donnie@localhost html]$

And, that's all there is to it.

You can also use chcon and restorecon to change the context of an entire directory and its contents. For either one, just use the -R option. For example:

sudo chcon -R -t httpd_sys_content_t /var/www/html/
sudo restorecon -R /var/www/html/

(Remember:  -R stands for recursive.)

There's still one last thing to take care of, even though it isn't really affecting our ability to access this file. That is, I need to change ownership of the file to the Apache user:

[donnie@localhost html]$ sudo chown apache: index.html
[sudo] password for donnie:

[donnie@localhost html]$ ls -l
total 4
-rw-rw-r--. 1 apache apache 125 Nov 22 16:14 index.html
[donnie@localhost html]$
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.196.217