nerdexam
Linux_Foundation

LFCS · Question #393

An SELinux security context is required to ensure that all files in /opt have the default context of system_u:object_r:usr_t. How should the corresponding configuration entry be formatted?

The correct answer is B. /opt/.* system_u:object_r:usr_t. To configure the default SELinux context for all files under /opt, the configuration entry should specify the regular expression ^/opt(/.)?$ or ^/opt/.$ followed by the desired context system_u:object_r:usr_t.

Submitted by alyssa_d· Apr 18, 2026Operation of Running Systems

Question

An SELinux security context is required to ensure that all files in /opt have the default context of system_u:object_r:usr_t. How should the corresponding configuration entry be formatted?

Options

  • Asystem_u:object_r:usr_t /opt/*
  • B/opt/.* system_u:object_r:usr_t
  • C/opt/* system_u:object_r:usr_t
  • Dsystem_u:object_r:usr_t: /opt/.*
  • Esystem_u:object_r:usr_t /opt/.*

How the community answered

(37 responses)
  • B
    86% (32)
  • C
    8% (3)
  • D
    3% (1)
  • E
    3% (1)

Why each option

To configure the default SELinux context for all files under `/opt`, the configuration entry should specify the regular expression `^/opt(/.*)?$` or `^/opt/.*$` followed by the desired context `system_u:object_r:usr_t`.

Asystem_u:object_r:usr_t /opt/*

This format places the context before the path and uses a shell glob `*` instead of a regular expression, which is incorrect for SELinux file context configuration.

B/opt/.* system_u:object_r:usr_tCorrect

SELinux file context configuration entries, typically found in files like `file_contexts` or configured with `semanage fcontext`, use regular expressions to match file paths followed by the security context. The pattern `/opt/.*` (or more precisely `^/opt(/.*)?$`) correctly matches the `/opt` directory and all its contents, and the format `path_regexp context` is standard.

C/opt/* system_u:object_r:usr_t

This option uses a shell glob `*` instead of a regular expression, which is not how SELinux file contexts are defined in configuration files.

Dsystem_u:object_r:usr_t: /opt/.*

This format places the context before the path, includes an extra colon after the context, and uses a regular expression that doesn't fully match the common pattern for `/opt` and its contents.

Esystem_u:object_r:usr_t /opt/.*

This format places the context before the path, which is incorrect for common SELinux file context configuration files like `file_contexts` where the path regexp comes first.

Concept tested: SELinux file context configuration

Source: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/using_selinux/using-semanage-and-restorecon-to-manage-selinux-file-contexts_using-selinux

Topics

#SELinux#File Contexts#Security#Regular Expressions

Community Discussion

No community discussion yet for this question.

Full LFCS Practice