Red Hat Certified Systems Admin (RHCSA) EX200 Practice Exam

Access More Questions
How do you display all SELinux context for a file and restore default contexts if needed?
Correct Answer:
ls -Z filename; restorecon -v filename
Explanation:
You manage SELinux file contexts by showing the current context and then applying the policy’s default to the file. First, display the SELinux context for the file with ls -Z filename. This prints the security context currently assigned to that specific file, giving you a snapshot to verify. If you find it isn’t the correct default, restore it using restorecon -v filename. The restorecon command consults the SELinux policy and reapplies the default context for that path, and the -v option makes it show exactly what changes were made. This combination ensures you both verify and revert to the sanctioned context. Other approaches don’t fit as well: listing without a filename shows contexts for multiple items rather than a single file; changing the context with chcon sets a new, user-specified context rather than the policy’s default; getenforce only reports whether SELinux is enforcing; and using restorecon without -v would still restore correctly but wouldn’t provide visibility into the changes.

Access more questions from this quiz

Continue to Red Hat Certified Systems Admin (RHCSA) EX200 Practice Exam for more practice questions and the full quiz experience.

Access More Questions