Contents
How to change SELinux context in restorecon command?
Here should give specify the full-path of the filename including the directory. To specify this input file in the restorecon, use the -f option as shown below. This will change the SELinux context for only about.html and data.html as shown below. Use ls -lZ command to verify that only those two files security context is changed.
How to restore SELinux to the full path?
In the following example, we are processing all the files under /var/www/html directory, but excluding the files from /var/www/html/sales sub-directory. Please note that you should use the full-path of the directory in the -e option.
How to do a dry run on SELinux?
Instead of really changing the SELinux context of the files, you can just view what files might potentially get changed by using -n option. The -n option is like a dry-run. When you use this, it will go through all the motions of executing the restorecon command, but will not really do anything.
How to use LS-LZ to restore SELinux?
Use ls -lZ command to verify that only those two files security context is changed. Note: Instead of specifying input.txt, you can also specify – which will ask for list of input files from the standard input. 7.
Which is an example of a restorecon command?
In the following example, we are storing the list of files that got affected by the restorecon command in the changed.log file. As we expect this changed.log file will contain the list of affected filenames along with full path as shown below. 6. Restore Context Based on Input File
How to create input.txt file in restorecon?
In the following, under /var/www/html directory, all these files currently has wrong security context. Create a input.txt file as shown below, which will have only two files. Here should give specify the full-path of the filename including the directory. To specify this input file in the restorecon, use the -f option as shown below.
How to change the context of SELinux in sbin?
When changing the SELinux context with /usr/sbin/semanage fcontext -a, use the full path to the file or directory to avoid files being mislabeled after a file system relabel, or after the /sbin/restorecon command is run.
Why is it important to have proper SELinux context?
On your Linux server, having proper SELinux security context for files and directories is very important. When you add your custom file to a directory that is already managed by SELinux policy, and if your custom file doesn’t have the proper SELinux context, then you will not get the expected result.
What does restorecon do if a file does not have a context?
If a file object does not have a context, restorecon will write the default context to the file object’s extended attributes. If a file object has a context, restorecon will only modify the type portion of the security context. The -F option will force a replacement of the entire context.