Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Labels

Direct answer

SELinux labels are stored in each file's extended attributes and assigned by policy rules (file contexts), at creation or by restorecon. Ports and other objects have labels too.

When to use this

Use it when relabelling after moving data, adding custom directories or ports.

First 30 seconds

1. matchpathcon <path> vs ls -Z <path> — differ?

2. restorecon -Rv <path>.

3. Ports: semanage port -l | grep <type>.

4. Add port: semanage port -a -t http_port_t -p tcp 8081.

5. Retest.

Operational verification

policy file-context rules → labels assigned → domains access by type

Evidence · next step

For SELinux → Labels, 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 Labels. 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 relabelling after moving data, adding custom directories or ports.
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.

5 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

policy file-context mapping → filesystem label → process/object access → restore/relabel behavior → AVC/workload

Healthy evidence: persistent mappings produce the expected labels, restorecon is idempotent and the workload succeeds in enforcing mode

Step 2 Verification and output interpretation Verify boundary

Verification chain. policy file-context mapping → filesystem label → process/object access → restore/relabel behavior → AVC/workload

Step 3 Commands Verify boundary
semanage fcontext -a -t httpd_sys_content_t '/srv/www(/.*)?'
restorecon -Rv /srv/www
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: temporary chcon hides a wrong mapping, path regex is too broad/narrow, relabel changes state unexpectedly, filesystem lacks labels or workload still fails after correct labeling

Step 5 Common mistakes Narrow the fault
  • Using chcon (not persistent across relabel).
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

Default labels come from semanage fcontext rules; restorecon applies them. Ports: semanage port -l. A full relabel (/.autorelabel) fixes widespread label problems.

Key checks
  • matchpathcon <path> — default context for a path
  • 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 & boundaries5 sections · depth on demand

What this shows and what it does not

Label remediation is complete only when the persistent mapping is correct and a restore/relabel reproduces the intended context before the original workload is retested.

In depth

SELinux file labels: rules, relabelling and persistence

File labels come from file context rules in the policy, which map path patterns to types. The semanage-fcontext(8) manual page describes local rules:

  • semanage fcontext -a -t <type> "<regex>" adds one. The pattern is a full path or a PCRE regular expression.
  • -l lists rules, and -C lists only local customisations. -d deletes and -m modifies.
  • -e makes one tree use the same labels as another, for example /home1 labelled like /home.
  • After adding a rule, run restorecon to apply it to existing files.

The restorecon(8) manual page adds:

  • Normally only the type is changed. -F resets the whole context.
  • -n together with -v shows what would change, without changing anything.
  • Files with a "customizable" type are only reset with -F.

Labelling tools and their effect

ToolEffectSurvives a relabel?
semanage fcontext + restoreconRule in the policy, then appliedYes
chcon -t type fileChanges the label directlyNo: restorecon or a relabel reverts it
restorecon -Rv pathApply the rules to existing files—
touch /.autorelabel + rebootRelabel the whole file system—
fixfilesRelabel tools, wrapping restorecon—

Common patterns

NeedRule
Web content in /srv/wwwsemanage fcontext -a -t httpd_sys_content_t "/srv/www(/.*)?"
A writable upload directory for the web appsemanage fcontext -a -t httpd_sys_rw_content_t "/srv/www/uploads(/.*)?"
Database data on another volumesemanage fcontext -a -e /var/lib/pgsql /data/pgsql
Home directories in /export/homesemanage fcontext -a -e /home /export/home

Rule precedence

Local rules are checked from newest to oldest, and the first match wins. Keep the regular expressions specific, so a broad rule doesn't override a narrower one.

host$ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/srv/www/uploads(/.*)?"
host$ sudo semanage fcontext -l -C
SELinux fcontext                type               Context
/srv/www(/.*)?                  all files          system_u:object_r:httpd_sys_content_t:s0
/srv/www/uploads(/.*)?          all files          system_u:object_r:httpd_sys_rw_content_t:s0
host$ sudo restorecon -Rvn /srv/www | head -3
Would relabel /srv/www/uploads from system_u:object_r:httpd_sys_content_t:s0 to system_u:object_r:httpd_sys_rw_content_t:s0
host$ sudo restorecon -Rv /srv/www
host$ matchpathcon /srv/www/uploads/avatar.png
/srv/www/uploads/avatar.png     system_u:object_r:httpd_sys_rw_content_t:s0

Check before you relabel

restorecon -Rvn shows what would change, which is valuable on large trees. matchpathcon shows the label a path should get under the current rules. That's useful for checking a rule before any files exist.

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

Labels is part of SELinux → Labels. SELinux Labels covers how filesystem/object labels are assigned, restored and persisted through policy file-context mappings, relabel operations and package/service expectations.

Topic-specific state model. SELinux Labels covers how filesystem/object labels are assigned, restored and persisted through policy file-context mappings, relabel operations and package/service expectations.

Interpretation rule. - chcon success ≠ persistent label assignment across relabel or restorecon.

  • Correct label on one file ≠ parent tree, alternate paths or newly created files inherit correctly.

Quick reference

File labels come from policy rules matching paths (semanage fcontext -l); restorecon applies them. Moving files keeps their old label, copying assigns the destination's — a classic cause of denials after mv.

matchpathcon /srv/www/index.html          # what the label should be
ls -Z /srv/www/index.html                  # what it is
semanage fcontext -a -t httpd_sys_content_t '/srv/www(/.*)?'
restorecon -Rv /srv/www
chcon -t httpd_sys_content_t /srv/www/test.html    # temporary, lost on relabel

Use semanage fcontext + restorecon for permanent changes; chcon only for quick tests.

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. Label remediation is complete only when the persistent mapping is correct and a restore/relabel reproduces the intended context before the original workload is retested.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. Labels owns persistent SELinux object labeling; Contexts owns interpretation of the resulting security context.

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 → Labels. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://selinuxproject.org/page/Main_Page · confidence 94%
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 labelsrestorecon labelssemanage fcontext
Embedded reference data

Quick lookup tables

Labels operational reference

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

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateSELinux Labels covers how filesystem/object labels are assigned, restored and persisted through policy file-context mappings, relabel operations and package/service expectations.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 chainpolicy file-context mapping → filesystem label → process/object access → restore/relabel behavior → AVC/workloadTrace requested/configured state through effective state to the observed workload result.
Failure boundaryLabel remediation is complete only when the persistent mapping is correct and a restore/relabel reproduces the intended context before the original workload is retested.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux security/trust evidence can establish this proof path: policy file-context mapping → filesystem label → process/object access → restore/relabel behavior → AVC/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. Label remediation is complete only when the persistent mapping is correct and a restore/relabel reproduces the intended context before the original workload is retested.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.

Labels · operational reference

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

Reference boundaryLabels
Topic pathSELinux → Labels
Runtime stateSELinux Labels covers how filesystem/object labels are assigned, restored and persisted through policy file-context mappings, relabel operations and package/service expectations.
Fast checks- Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for Labels. - 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 chainpolicy file-context mapping → filesystem label → process/object access → restore/relabel behavior → AVC/workload Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary.
Failure boundaryLabel remediation is complete only when the persistent mapping is correct and a restore/relabel reproduces the intended context before the original workload is retested. 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.
Confirmation

Confirm action

Continue?