Using restorecon for restoring the default context

Using the restorecon command is the most popular and preferred way of modifying the SELinux context of a file or directory. As is visible from the name of the restorecon command, it is used to restore the default context of a file or directory by reading the default rules set in the SELinux policy. If the wrong context is applied, restorecon automatically corrects it from the policy of the filesystem.

In the following example, we simulate a problem scenario, in which a file has incorrect syntax and we correct it using the restorecon command:

The restorecon command is a part of the policycoreutil ...

Get CentOS Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.