Restoring changed file contexts to the default policy
In the previous section, we mentioned how semanage
enables us to perform changes to the policy, which is the recommended way to perform changes and to persist them for future files and folders, but that is not the only way we can perform operations.
From the command line, we can use the chcon
utility to change the context for a file. This will allow us to define the user, the role, and the type for the file we want to alter, and similar to other filesystem utilities such as chmod
or chown
, we can also affect files recursively, so it's easy to set a full folder hierarchy to the desired context.
One feature that I always found very interesting is the ability to copy the context of a file via the --reference
flag, so that the same context as the referenced file is applied to the target one.
When we were introducing the example of httpd
earlier in this chapter, we did a test with two files, index1.htm
and index2.htm
, that...