2

I am using SELinux in my centos server. I am trying to change context of the file located in the /var/www/html as a root user.

Root user is also not able to make any changes in the context of the file. Let me know how could a root user change the context the file in Selinux.

The context of the root user is as follows

unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
0

2 Answers 2

2

Use chcon to switch the SELinux context, ex:

chcon system_u:object_r:httpd_sys_content_t:s0 /var/www/html
0

Are you trying to put the file in question in the default context for its current location? (i.e. put it in the context that would be typical for a file in /var/lib/www)

If so you can use restorecon

restorecon -v /var/lib/www/my_file.txt

You can use -n to see what restorecon will change without actually changing anything

restorecon -v -n /var/lib/www/my_file.txt

You must log in to answer this question.