Question: How to check if files and directories have the correct SELinux security context?
To check the current SELinux security context of files or directories, use matchpathcon command with -V option as the Linux root user:
# matchpathcon -V /home/* /home/dkwon verified /home/qmin has context system_u:object_r:usr_t, should be user_u:object_r:user_home_dir_t
This will verify that actual file context on disk matches the defaults in the SELinux policy. Then it prints the result as shown above. In the example, /home/qmin directory has been labeled with usr_t type, but it should be labeled with the user_home_dir_t. Whereas the /home/dkwon directory has successfully verified.
For more information, refer its manual page:
# man matchpathcon
To apply the directory the default security context, run the restorecon command:
# restorecon -v /home/qmin