hardMultiple Choice
XK0-006 Practice Question: An administrator is troubleshooting a web server…
An administrator is troubleshooting a web server that is running under SELinux enforcing mode. The web content is located in a non-standard directory /webfiles. Using the standard SELinux context 'httpd_sys_content_t', the files are still inaccessible. Which command will properly set the context recursively and persist across relabels?
⚠ Common exam trap
It's easy for candidates to think `restorecon` alone is sufficient to set a custom context, forgetting that it only applies the default policy mapping; without a prior `semanage fcontext` entry, the context will not persist across relabels.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
semanage fcontext -a -t httpd_sys_content_t '/webfiles(/.*)?' ; restorecon -Rv /webfiles
`semanage fcontext -a -t httpd_sys_content_t '/webfiles(/.*)?'` adds a file-context mapping to the SELinux policy database, ensuring the context survives a `restorecon` or filesystem relabel. The subsequent `restorecon -Rv /webfiles` applies that context recursively to the directory. Without the `semanage` entry, `restorecon` alone would revert to the default context (often `default_t`), which is not accessible by httpd.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
semanage fcontext -a -t httpd_sys_content_t '/webfiles(/.*)?' ; restorecon -Rv /webfiles
Why this is correct
semanage fcontext writes a persistent mapping into the SELinux file-context policy for the /webfiles path, and restorecon applies it recursively to the files. This satisfies the stem's requirement that the context survive future relabels, which chcon alone cannot guarantee.
- ✗
chcon -R -t httpd_sys_content_t /webfiles
Why it's wrong here
chcon applies the context directly but writes no persistent policy entry, so a full filesystem relabel reverts /webfiles to default_t and access breaks again. It is tempting because it sets httpd_sys_content_t immediately and recursively, which is exactly what a temporary test or a path already covered by policy would need.
- ✗
setenforce 0
Why it's wrong here
setenforce 0 switches SELinux to permissive mode, disabling enforcement entirely rather than labelling /webfiles, so it neither sets httpd_sys_content_t nor persists as a context change. It is tempting as a quick troubleshooting step to confirm SELinux is the blocker, but it leaves the server unprotected and the mislabelling unresolved.
- ✗
restorecon -Rv /webfiles
Why it's wrong here
restorecon resets files to the context defined by the active SELinux policy for their path, so a non-standard directory like /webfiles has no matching policy rule and the files revert to default_t, remaining inaccessible. It is tempting because restorecon persists across relabels, but it requires a prior semanage fcontext mapping to work here.
Go deeper
Related to this question
About these practice questions
One of 781 original XK0-006 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This XK0-006 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the XK0-006 exam.