Question 9 of 510
SecurityhardMultiple ChoiceObjective-mapped

Quick Answer

The correct answer is to use semanage fcontext to define the default context for the file and then run restorecon. This is the most appropriate persistent SELinux file context configuration because semanage fcontext writes a rule to the SELinux policy that survives file system relabeling, unlike chcon which only applies a temporary label that can be overwritten. On the CompTIA Linux+ XK0-005 exam, this question tests your understanding of the difference between temporary and persistent context changes, a common trap where candidates mistakenly choose chcon for a permanent fix. The key distinction is that semanage fcontext modifies the file_contexts database, making the rule stick even after a full system relabel or restorecon operation. Remember the mnemonic: "semanage sets the stage, restorecon plays the part" — semanage defines the rule, restorecon applies it to the actual file.

XK0-005 Security Practice Question

This XK0-005 practice question tests your understanding of security. This is a configuration task: choose the command set that satisfies every stated requirement. Small differences — like 'secret' vs 'password' or 'transport input ssh' vs 'all' — change whether the answer is correct. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

A Red Hat Enterprise Linux 8 system is configured with SELinux in enforcing mode. A custom application needs to write to a file in /var/log. The audit log shows an AVC denial for httpd_t attempting to write to var_log_t. Which of the following is the most appropriate persistent solution?

Question 1hardmultiple choice
Full question →

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

Use semanage fcontext to define the default context for the file and then restorecon.

Option D is correct because semanage fcontext defines a persistent default SELinux file context rule, which survives file system relabeling. After defining the rule, restorecon applies the context to the file. This ensures the custom application's log file is labeled httpd_log_t, allowing httpd_t to write to it, while chcon (option C) only makes a temporary change that can be overwritten by restorecon or a relabel.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Set the SELinux boolean httpd_can_network_connect to on.

    Why it's wrong here

    Unrelated to file write permissions.

  • Change the ownership of the file to apache.

    Why it's wrong here

    Does not affect SELinux policy.

  • Use chcon to set the file context to httpd_log_t.

    Why it's wrong here

    Immediate but will not survive a restorecon or relabel.

  • Use semanage fcontext to define the default context for the file and then restorecon.

    Why this is correct

    Persistent method; sets default context in policy.

    Related concept

    Read the scenario before looking for a memorised answer.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap here is that candidates confuse chcon (temporary) with semanage fcontext (persistent), or mistakenly think changing Unix ownership or enabling a network boolean will resolve a file-based SELinux denial.

Detailed technical explanation

How to think about this question

SELinux uses type enforcement (TE) where a domain (e.g., httpd_t) must have a specific type transition or allow rule to write to a target type (e.g., httpd_log_t). The semanage fcontext command adds a rule to the file_contexts.local file, which is consulted by restorecon and setfiles during relabeling. Without this persistent rule, any temporary context change via chcon is overwritten by the next restorecon, making the application fail again after maintenance.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A practitioner preparing for the XK0-005 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related XK0-005 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free XK0-005 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this XK0-005 question test?

Security — This question tests Security — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: Use semanage fcontext to define the default context for the file and then restorecon. — Option D is correct because semanage fcontext defines a persistent default SELinux file context rule, which survives file system relabeling. After defining the rule, restorecon applies the context to the file. This ensures the custom application's log file is labeled httpd_log_t, allowing httpd_t to write to it, while chcon (option C) only makes a temporary change that can be overwritten by restorecon or a relabel.

What should I do if I get this XK0-005 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

2 more ways this is tested on XK0-005

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Scenario: A cloud hosting company uses SELinux in enforcing mode on all Linux servers. A developer reports that a custom web application running under Apache (httpd) is unable to write log files to /var/log/myapp/. The directory /var/log/myapp/ has permissions 755 and is owned by root:root. The httpd process runs as the 'apache' user. The administrator checks SELinux context: /var/log/myapp is labeled with default_t type. The administrator wants to allow httpd to write to this directory while maintaining security. Which command should the administrator run?

medium
  • A.Change ownership with 'chown apache:apache /var/log/myapp'
  • B.Run 'setenforce 0' to disable SELinux
  • C.Run 'chcon -t httpd_log_t /var/log/myapp'
  • D.Run 'semanage fcontext -a -t httpd_log_t "/var/log/myapp(/.*)?"' and then 'restorecon -Rv /var/log/myapp'

Why D: Option D is correct because it permanently relabels the directory with the httpd_log_t SELinux type, which is specifically designed to allow Apache (httpd) to write log files. The semanage fcontext command adds a file context mapping to the SELinux policy database, and restorecon applies that mapping to the filesystem. This approach maintains SELinux enforcing mode and does not rely on temporary changes like chcon or insecure workarounds like disabling SELinux.

Variation 2. A web server on RHEL 8 is serving content from a non-default directory /data/web. The SELinux context is set to default_t for the directory, causing access denials. Which command should be used to set the correct context for web content?

medium
  • A.setsebool -P httpd_can_network_connect on
  • B.restorecon -R /data/web
  • C.chcon -t httpd_sys_content_t /data/web
  • D.semanage fcontext -a -t httpd_sys_content_t "/data/web(/.*)?"

Why D: Option B (semanage fcontext) is the persistent method to set SELinux file contexts. Option A (chcon) is immediate but not permanent; Option C (restorecon) would restore to the current policy default, which may not be correct; Option D sets a boolean unrelated to context.

Last reviewed: Jun 25, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This XK0-005 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-005 exam.