Courseiva
System SecuritymediumMultiple ChoiceObjective-mapped

LPIC-2 System Security Practice Question

A system with SELinux in enforcing mode is running a custom application that needs to write to a file in /data. The application's context type is 'myapp_t', and the target file context is 'default_t'. The file's current context is 'var_t'. Which command changes the file's context to allow access?

⚠ Common exam trap

Watch out — candidates often confuse `chcon` (immediate context change) with `semanage fcontext` (policy database change) or `restorecon` (reset to policy default), and fail to realize that `chcon` is the only command that directly sets the file's context without requiring a subsequent relabel.

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 default_t /data/file

`chcon -t default_t /data/file` directly changes the SELinux type of the file to `default_t`, which matches the type expected by the `myapp_t` domain's access rules. Since the application runs in enforcing mode and needs to write to a file with type `default_t`, this command immediately sets the correct context without modifying the policy or requiring a relabel.

Answer analysis

Option-by-option breakdown

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

  • fixfiles -F relabel /data

    Why it's wrong here

    Relabels entire file system according to policy.

  • chcon -t default_t /data/file

    Why this is correct

    Directly changes the file's type to default_t.

  • semanage fcontext -a -t default_t /data/file

    Why it's wrong here

    Adds a file context rule but does not immediately apply; requires restorecon.

  • restorecon /data/file

    Why it's wrong here

    Restores to default policy context, not the desired one.

About these practice questions

Courseiva writes every LPIC-2 question from scratch — 507 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This LPIC-2 practice question is part of Courseiva's free LPI 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 LPIC-2 exam.