hardMultiple Choice
XK0-006 Practice Question: An application is being denied access to a file…
An application is being denied access to a file due to SELinux. Which command can be used to temporarily set the SELinux context of the file to match the expected type for the application?
⚠ Common exam trap
Many exam-takers confuse `chcon` (temporary, immediate change) with `restorecon` (reverts to policy default) or `semanage fcontext` (persistent policy rule that requires an extra step to apply), leading them to pick an option that either disables SELinux or does not immediately fix the file context.
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
✓
chcon -t httpd_sys_content_t /var/www/html/index.html
The `chcon` command is used to temporarily change the SELinux context of a file without modifying the SELinux policy. By specifying `-t httpd_sys_content_t`, the file's type is set to the expected type for Apache (httpd) to access it, resolving the denial immediately. This change is not persistent across file system relabeling, making it ideal for temporary troubleshooting.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
chcon -t httpd_sys_content_t /var/www/html/index.html
Why this is correct
`chcon -t httpd_sys_content_t` directly relabels the file's SELinux type to `httpd_sys_content_t`, satisfying the stem's requirement to temporarily set a context matching the application's expected type. Unlike `semanage fcontext`, which writes persistent mapping rules, `chcon` changes only the live label, so the change is lost on relabelling.
- ✗
setenforce 0
Why it's wrong here
setenforce 0 switches the whole system into permissive mode, disabling enforcement globally rather than relabelling the file, so it does not set the expected type. It is tempting as a quick diagnostic to confirm SELinux is the cause, and would be appropriate for temporarily gathering denial evidence.
- ✗
restorecon -v /var/www/html/index.html
Why it's wrong here
restorecon resets a file's label to whatever the existing policy already defines, so it cannot assign a different expected type when the policy mapping is absent or wrong. It is tempting because it is the standard fix for mislabelled files, and would be correct after a file was moved or copied.
- ✗
semanage fcontext -a -t httpd_sys_content_t /var/www/html
Why it's wrong here
semanage fcontext only writes a persistent mapping into the file-context policy; the file's actual label stays unchanged until restorecon is run, so access remains denied. It is tempting because it is the correct permanent fix, and would be right when the labelling rule itself is missing from policy.
Visual reference
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.