How to Update Permissions in SELinux

If you haven’t worked with Security Enhanced Linux (SELinux) before, then you may have run into a frustrating issue when trying to update permissions in SELinux with chown or chmod commands.
The files show updated permissions when you run ls -l just fine…but for some reason, the web server refuses to serve files…even with 777 permissions across the board!
This is one of the features of SELinux, and requires an extra step to update permissions. Once you are familiar with the commands required, it is very easy to update permissions in SELinux.

Update the SELinux Permissions Cache

Changing the permissions with chmod or chown will only update the permissions ‘visually’. To actually fully update the permissions you need to run the restorecon command to update the permissions cache.

chown -R apache:apache /var/www/html
restorecon -Rv /var/www/html

 
Are there any gotchas you have encountered while using Linux or SELinux? Leave a comment below and please share if you found this information useful!

Leave a Reply

Your email address will not be published. Required fields are marked *