Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Contexts

Direct answer

An SELinux context (label) has user:role:type:level, e.g. system_u:object_r:httpd_sys_content_t:s0. The type is what most policy rules use.

When to use this

Use it when a service cannot access files that have the wrong type.

First 30 seconds

1. ls -Z <path> — type?

2. Expected type: semanage fcontext -l | grep <path> or matchpathcon <path>.

3. Fix: restorecon -Rv <path>.

4. Custom path: semanage fcontext -a -t <type> '<path>(/.*)?' + restorecon.

5. Retest the service.

Operational verification

file label (type) and process domain → policy allows the domain to access the type

Evidence · next step

For SELinux → Contexts, continue with the first unproven Topic check: Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for Contexts. If that boundary is healthy, advance to the adjacent check: Read back the effective runtime state and precedence rather than assuming an edited file, package state or service status is active. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it when a service cannot access files that have the wrong type.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

7 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

process domain + file/socket/port context → policy type rules/transition → AVC decision → operation → workload

Healthy evidence: processes and objects carry expected persistent contexts, transitions occur as designed and workload operations match policy

Step 2 Verification and output interpretation Verify boundary

Verification chain. process domain + file/socket/port context → policy type rules/transition → AVC decision → operation → workload

Step 3 Specialized verification Verify boundary

Display contexts on the process and every relevant file/path component, then compare file labels with the expected policy mapping. Use restorecon in check/verbose mode to find drift before changing it. For a denial, match source domain and target type from the AVC to the observed objects. After applying a persistent mapping and relabel, repeat the real access under the original service domain. A correct-looking label alone is not evidence the policy permits the requested class/permission.

Step 4 Commands Verify boundary
ls -Z /var/www/html
ps -eZ | grep httpd
id -Z
Step 5 Failure modes and next checks Narrow the fault

Suspicious evidence: wrong type/domain, unexpected transition, unlabeled/default context, context differs across paths or labels are modified without persistent mapping

Step 6 Special cases and limits Narrow the fault

Pathnames do not determine access directly; the resolved object’s label participates in policy. Two files with the same Unix owner/mode can have different SELinux outcomes. Moving content between filesystems or restoring from backup can alter xattrs. Context correctness does not override DAC or application policy. Keep persistent mapping, actual xattr, process domain and requested permission as separate evidence.

Step 7 Common mistakes Narrow the fault
  • Moving files with mv and keeping the old context.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

Files moved with mv keep their old label; copied files get the target directory's label. Set permanent rules with semanage fcontext -a -t <type> '<path>(/.*)?' then restorecon -Rv <path>. chcon changes are lost on relabel.

Key checks
  • getenforce / sestatus — mode and policy
  • ls -Z <path> — file context
  • ps -eZ | grep <proc> — process context
  • ausearch -m AVC -ts recent — recent denials
  • semanage fcontext -l | grep <path> — context rules for a path
ReferenceImportant terms & boundaries6 sections · depth on demand

What this shows and what it does not

Context diagnosis is resolved when the exact subject/object contexts are resolved and matched to policy expectations for the failing operation.

In depth

SELinux contexts: user, role, type and level

Every process and every object (file, port, socket) has an SELinux context. Red Hat's SELinux guide says it has four fields: user, role, type and security level. In the targeted policy, the type does almost all the work: policy rules decide which process types (domains) may access which object types. Types end in _t. For example, httpd_t (the web server domain) may read httpd_sys_content_t (web content).

The four fields

FieldExampleRole in the targeted policy
SELinux usersystem_u, unconfined_u, staff_uMaps Linux users to allowed roles
Rolesystem_r, object_robject_r for files; roles for processes
Typehttpd_t, httpd_sys_content_tThe main access control decision
Levels0, s0:c1,c5MLS/MCS: sensitivity and categories (used by containers and VMs)

Seeing contexts

ObjectCommand
Filesls -Z, stat -c %C
Processesps -eZ, id -Z (your own)
Portssemanage port -l
Network connectionsss -Z

Process and file types together

ServiceProcess typeFiles it may read or write
Apache, nginxhttpd_thttpd_sys_content_t (read), httpd_sys_rw_content_t (write), httpd_log_t
sshdsshd_tssh_home_t (~/.ssh), sshd_key_t
PostgreSQLpostgresql_tpostgresql_db_t
Containers (podman)container_tcontainer_file_t, with unique MCS categories per container

MCS categories

Container engines and libvirt give each container or VM a unique pair of categories, such as s0:c112,c907. Even with the same type, one container can't access another's files, because their categories differ.

host$ ps -eZ | grep -E "nginx|sshd" | head -3
system_u:system_r:httpd_t:s0         1203 ?        00:00:00 nginx
system_u:system_r:sshd_t:s0-s0:c0.c1023 842 ?      00:00:00 sshd
host$ id -Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
host$ ls -Zd /var/www/html /home/alice/.ssh /var/lib/pgsql/data
system_u:object_r:httpd_sys_content_t:s0 /var/www/html
unconfined_u:object_r:ssh_home_t:s0 /home/alice/.ssh
system_u:object_r:postgresql_db_t:s0 /var/lib/pgsql/data
host$ podman run -d --name web1 nginx && ps -eZ | grep container_t | head -2
system_u:system_r:container_t:s0:c112,c907 22011 ? 00:00:00 nginx
host$ sudo semanage port -l | grep -w http_port_t
http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000

Reading the port list

http_port_t covers the ports httpd_t may bind to. A web server configured for port 8081 would be denied, until that port is added with semanage port -a.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

Contexts is part of SELinux → Contexts. SELinux Contexts are security labels associated with subjects and objects, typically represented as user:role:type:level, with type/domain commonly driving targeted-policy access decisions.

Topic-specific state model. SELinux Contexts are security labels associated with subjects and objects, typically represented as user:role:type:level, with type/domain commonly driving targeted-policy access decisions.

Interpretation rule. - A context string exists ≠ it is the expected policy context for that path/process.

  • Matching Unix owner/mode ≠ matching SELinux type or domain.

Specialized mechanics

An SELinux security context is commonly represented as user:role:type:level, with type usually driving type-enforcement decisions for files and processes. Process domains are types applied to processes; file types label objects. Current file context is stored as extended metadata, while the policy’s file-context database defines the expected default label for path patterns. A copied/moved file can retain or acquire labels differently depending on operation and destination semantics.

Quick reference

SELinux contexts have four fields: user:role:type:level, e.g. system_u:object_r:httpd_sys_content_t:s0. Type enforcement uses mostly the type; MLS/MCS uses the level (containers get unique categories like s0:c123,c456 to isolate them from each other).

id -Z
ps -eZ | grep sshd
ls -Z /etc/shadow
seinfo -t | grep httpd             # setools-console
sesearch -A -s httpd_t -t httpd_sys_content_t -c file

Process types transition on exec according to policy (e.g. init_t executing httpd_exec_t becomes httpd_t).

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. Context diagnosis is resolved when the exact subject/object contexts are resolved and matched to policy expectations for the failing operation.

ReferenceConfiguration & state2 sections · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. Contexts owns interpretation of SELinux subject/object security contexts.

Specialized lifecycle

Use policy-aware tools to define persistent path-to-type mappings and apply them. semanage fcontext adds local mappings; restorecon reconciles object labels against the policy mapping. Avoid relying on chcon for durable configuration because relabel operations can restore policy defaults. When designing service content paths outside standard locations, select the documented type for the service rather than granting broad access to a generic type. Account for mount labeling options on filesystems that cannot store normal xattrs.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in SELinux → Contexts. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://selinuxproject.org/page/Main_Page · confidence 94%
2026-09-13 · vendor docSELinux on RHEL 9 RHEL 9

Authoritative Linux project/vendor documentation reviewed for bounded reference claims: SELinux security contexts, file labeling and policy applicability. Documentation-based technical verification only; not lab or production-runtime proof. The schema vendor_doc method is used for authoritative project/vendor documentation; deployment applicability remains separate evidence.

Basis: https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/using_selinux/ · confidence 93%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
selinux contextsselinux security contextselinux type context
Embedded reference data

Quick lookup tables

Contexts operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Contexts.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateSELinux Contexts are security labels associated with subjects and objects, typically represented as user:role:type:level, with type/domain commonly driving targeted-policy access decisions.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin host + boot/time + real identity/workload → identify authoritative policy/key/trust source → read back loaded/effective runtime state → reproduce one safe allow/deny/handshake test → correlate audit/service/kernel evidence → locate first failed boundary → make the smallest persistent change → repeat original workload + regression/recovery check.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chainprocess domain + file/socket/port context → policy type rules/transition → AVC decision → operation → workloadTrace requested/configured state through effective state to the observed workload result.
Failure boundaryContext diagnosis closes when the exact subject/object contexts are resolved and matched to policy expectations for the failing operation.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux security/trust evidence can establish this proof path: process domain + file/socket/port context → policy type rules/transition → AVC decision → operation → workloadUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove unobserved identities, objects, policies, namespaces, endpoints or time periods. Context diagnosis closes when the exact subject/object contexts are resolved and matched to policy expectations for the failing operation.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven security/trust boundary, capture the adjacent effective state and audit/handshake evidence, make only the demonstrated persistent change, then repeat the original workload plus recovery/regression checks.Continue to the next unresolved boundary while preserving the original test condition.

Contexts · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundaryContexts
Topic pathSELinux → Contexts
Runtime stateSELinux Contexts are security labels associated with subjects and objects, typically represented as user:role:type:level, with type/domain commonly driving targeted-policy access decisions.
Fast checks- Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for Contexts. - Read back the effective runtime state and precedence rather than assuming an edited file, package state or service status is active. - Reproduce one safe allowed/denied or handshake/access test and correlate kernel/service/audit evidence at the first relevant boundary. - Apply the smallest persistent cause-specific change, then repeat the original test plus an adjacent regression/recovery check.
Verification chainprocess domain + file/socket/port context → policy type rules/transition → AVC decision → operation → workload Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary.
Failure boundaryContext diagnosis closes when the exact subject/object contexts are resolved and matched to policy expectations for the failing operation. Boundary chain: process credentials/namespace → path/mount lookup → DAC/ACL/LSM → filesystem metadata → block/device/backend → completion/read-back.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.

Contexts · specialized operational reference

Topic-specific Linux mechanics, lifecycle, proof path and failure-boundary lookup.

Operational boundaryTopic-specific reference
FormatSELinux user : role : type : level
File truthCurrent xattr vs policy file-context mapping
Persistencesemanage fcontext; restorecon applies mapping
ProofCorrect process domain/target type + allowed original access
Confirmation

Confirm action

Continue?