Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

SELinux

Direct answer

SELinux is mandatory access control on RHEL-family systems: every process and file has a security context, and the policy decides which domains may access which types, regardless of Unix permissions.

When to use this

Use it when SELinux blocks a service, or when deploying a service with custom paths or ports on RHEL.

First 30 seconds

1. getenforce — Enforcing?

2. ausearch -m AVC -ts recent — denial with scontext, tcontext, tclass?

3. Wrong label → restorecon -Rv <path> (or semanage fcontext -a + restorecon).

4. Boolean → getsebool -a | grep <service>; setsebool -P <bool> on.

5. Non-standard port → semanage port -a -t <type> -p tcp <port>.

Operational verification

process domain and file type → policy rule checked → allowed or AVC denial logged

Evidence · next step

For SELinux, 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 SELinux. 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
Key commandgetenforce
Scope / prerequisiteUse it when SELinux blocks a service, or when deploying a service with custom paths or ports on RHEL.
Reference · 4
What next?3 suggested next steps
Child topics (this level)6
Catalog command links4
Evidence1
On this pageJump to a specific section
Linux command reference

Primary Commands

Configuration and operational commands for this Topic.

getenforceReference
getenforce

Return the current SELinux enforcement mode as Enforcing, Permissive or Disabled.

Use when: Primary lookup intent: verify. Use getenforce when the lookup goal is to return the current SELinux enforcement mode as Enforcing, Permissive or Disabled. Tie the result to the same host, namespace, user identity and time window as the symptom.

Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: verify. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. getenforce is documented as an operational lookup primitive under SELinux. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.

Linux · policy
sestatusReference
sestatus

Summarize SELinux enablement, policy, enforcement mode and related filesystem state.

Use when: Primary lookup intent: verify. Use sestatus when the lookup goal is to summarize SELinux enablement, policy, enforcement mode and related filesystem state. Tie the result to the same host, namespace, user identity and time window as the symptom.

Quick note: Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: verify. Safety class: read_only. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. sestatus is documented as an operational lookup primitive under SELinux. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.

Linux · policy
restoreconReference
restorecon

Reset SELinux file contexts to the labels defined by the active labeling policy.

Use when: Primary lookup intent: configure. Use restorecon when the lookup goal is to reset SELinux file contexts to the labels defined by the active labeling policy. Tie the result to the same host, namespace, user identity and time window as the symptom.

Quick note: Post-change verification for restorecon: Verify effective labels/policy and rerun the original confined workload access. Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: configure. Safety class: changes_state. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. restorecon is documented as an operational lookup primitive under SELinux. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.

Linux · policy
semanageReference
semanage

Manage persistent SELinux policy mappings such as ports, file contexts, users and booleans.

Use when: Primary lookup intent: configure. Use semanage when the lookup goal is to manage persistent SELinux policy mappings such as ports, file contexts, users and booleans. Tie the result to the same host, namespace, user identity and time window as the symptom.

Quick note: Post-change verification for semanage: Read back persistent policy mapping/effective labels and rerun the original confined workload. Output review: healthy and suspicious cues are command-specific interpretation boundaries, not fixed literal output samples. Intent class: configure. Safety class: changes_state. Intent describes the primary lookup role; safety remains command-family capability and can be higher than a read-only invocation. semanage is documented as an operational lookup primitive under SELinux. The canonical leaf intentionally represents the command family; options remain distribution/tool-version specific.

Linux · policy
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 + object label → DAC/capabilities → SELinux policy/boolean/transition → AVC allow/deny → audit → workload → persistent label/policy remediation

Healthy evidence: enforcing/permissive state is intentional, policy is loaded, contexts/transitions match expectations, AVC evidence is understood and workload behavior matches policy

Step 2 Commands Verify boundary
getenforce
sestatus
ausearch -m AVC -ts recent
ls -Z /var/www
Step 3 Verification and output interpretation Verify boundary

Verification path. Reproduce using the exact identity, service, path/object label and execution context. Separate authentication success from subsequent authorization. For SELinux/AppArmor, correlate denial records with current mode/profile/labels and confirm the access vector/path actually matches the failing operation. For hardening, verify both the intended denial and one required allowed workflow. Audit presence supports reconstruction but is not equivalent to evidence that policy blocked the action.

Verification chain. process domain + object label → DAC/capabilities → SELinux policy/boolean/transition → AVC allow/deny → audit → workload → persistent label/policy remediation

Step 4 Verification path Verify boundary

Exercise one safe negative or boundary case implied by UID/GID mismatch, stale group membership, ACL/mode conflict, missing capability, noexec/readonly mount, SELinux denial, AppArmor denial, expired/untrusted certificate or secret exposure.

Step 5 Failure modes and next checks Narrow the fault

Suspicious evidence: mode is permissive/disabled unexpectedly, labels drift, temporary chcon changes disappear, booleans/policy are broadened blindly, audit context is incomplete or disabling SELinux masks the real cause

Step 6 Common mistakes Narrow the fault
  • setenforce 0 as a permanent fix.
  • Moving files (keeping wrong context) instead of copying or restoring context.
Step 7 Where it fails Narrow the fault

Walk identity/group resolution → Unix mode/ACL/capability → mount/sandbox constraint → SELinux/AppArmor policy → credential/TLS trust → protected operation and stop where observed state diverges.

Common failure classes are UID/GID mismatch, stale group membership, ACL/mode conflict, missing capability, noexec/readonly mount, SELinux denial, AppArmor denial, expired/untrusted certificate or secret exposure.

Also consider stale generated config, wrong environment, wrong namespace/chroot/container, package/provider mismatch, dependency ordering, immutable/read-only mounts, exhausted inode/block resources, capabilities, SELinux/AppArmor denial, systemd sandboxing, cgroup limits and boot-time state that differs from the interactive shell.

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
Drill down

Subtopics

Go one level deeper into this subject.

Key points

Never disable SELinux to fix a problem: read the AVC denial and fix the label (restorecon, semanage fcontext), boolean (setsebool -P) or port (semanage port). Use permissive mode only briefly to confirm.

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
ReferenceWhy it matters1 section · depth on demand

How it works in operation

Permission denial can arise from path traversal, ACL, capabilities or SELinux/AppArmor independently.

ReferenceHow it works2 sections · depth on demand

How it works

Permission denial can arise from path traversal, ACL, capabilities or SELinux/AppArmor independently.

Quick reference

SELinux (Security-Enhanced Linux) is mandatory access control built into the kernel. On top of normal file permissions, every process and file carries a security label (context), and the loaded policy decides which process types may access which object types. Even a process running as root is confined to what its type is allowed to do, which limits the damage if a service is compromised.

ConceptMeaning
Contextuser:role:type:level, e.g. system_u:object_r:httpd_sys_content_t:s0
Type enforcementRules like "httpd_t may read httpd_sys_content_t"
ModesEnforcing (blocks and logs), Permissive (logs only), Disabled
BooleansSwitches for optional behaviour, e.g. httpd_can_network_connect
AVC denialLogged refusal in the audit log
getenforce; sestatus
ls -Z /var/www/html; ps -eZ | grep httpd
ausearch -m AVC -ts recent
semanage fcontext -a -t httpd_sys_content_t '/srv/web(/.*)?'
restorecon -Rv /srv/web
setsebool -P httpd_can_network_connect on
semanage port -a -t http_port_t -p tcp 8443

Most denials come from wrong file labels after copying or moving files, or from services using non-standard ports or paths. Fix the label, port or boolean rather than switching SELinux off; use audit2allow only after confirming the access is legitimate.

ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

SELinux is resolved when mode, policy and relevant contexts are confirmed, the first incorrect label/policy boundary is corrected minimally, and the original workload passes without broadening policy unnecessarily.

Permission denial can arise from path traversal, ACL, capabilities or SELinux/AppArmor independently.

In depth

Troubleshooting SELinux denials

Most SELinux work is understanding why something was denied, and fixing it properly. Red Hat's "Getting started with SELinux" guide describes the essentials:

  • Types: policy rules are written mostly in terms of types, which end in _t. For example, the web server domain httpd_t may read files labelled httpd_sys_content_t.
  • Denials: logged to /var/log/audit/audit.log as type=AVC messages.
  • Modes: setenforce switches between enforcing and permissive until the next reboot, and getenforce shows the current mode.
  • Per-domain permissive mode: one domain can be made permissive while the rest stays enforcing (semanage permissive -a httpd_t). Red Hat advises caution with this.

A troubleshooting sequence

StepCommandLooking for
1. Confirm it's SELinuxausearch -m AVC -ts recentDenials at the time of the failure
2. Read the denialausearch -m AVC -ts recent -iThe source type, the target type and class, the permission
3. Get an explanationsealert -a /var/log/audit/audit.log (setroubleshoot)Suggested fixes
4. Choose the fix—See the table below
5. VerifyRepeat the action; check for new AVCs—

Choosing the right fix

CauseFix
Files in a non-standard locationsemanage fcontext -a -t <type> '<path>(/.*)?' + restorecon -Rv <path>
Labels lost after copying or restoringrestorecon -Rv <path>
A service on a non-standard portsemanage port -a -t http_port_t -p tcp 8081
An optional behaviour (e.g. httpd connecting to the network)setsebool -P httpd_can_network_connect on
A genuinely new needA local policy module from audit2allow (review it first)
Testing onlysetenforce 0 briefly, never as a fix
host$ sudo ausearch -m AVC -ts recent -i | tail -1
type=AVC msg=audit(28/11/26 15:02:11.412:8812) : avc:  denied  { read } for  pid=1204 comm=nginx name=index.html dev="dm-3" ino=1835210 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0
host$ ls -Z /srv/www/intranet/index.html
unconfined_u:object_r:default_t:s0 /srv/www/intranet/index.html
host$ sudo semanage fcontext -a -t httpd_sys_content_t "/srv/www(/.*)?"
host$ sudo restorecon -Rv /srv/www
Relabeled /srv/www/intranet/index.html from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
host$ sudo ausearch -m AVC -ts recent | grep -c nginx
0

Reading the denial

nginx (httpd_t) was denied read on a file labelled default_t. That type is what files get in directories the policy doesn't know about. The fix is a file context rule for the directory, not a policy change. After relabelling, the file has httpd_sys_content_t, and no new denials appear.

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

Runtime state ownership and mechanics. Linux security composes authentication (PAM and service mechanisms), identity/credentials, DAC permissions/ACLs, capabilities, LSM policy such as SELinux/AppArmor, audit and service/network policy. These controls are cumulative: passing one layer does not bypass another. SELinux labels/types and AppArmor path/profile rules differ in policy model, while auditd records selected security-relevant events rather than making authorization decisions.

Topic-specific state model. SELinux is the dedicated operational reference for label-based mandatory access control: runtime mode, loaded policy, process domains, object types/labels, transitions and AVC evidence are traced to the application operation.

Technical metadata. Linux distribution/kernel + boot/time + user/group/process/service identity + PAM/SSH/DAC/ACL + SELinux/AppArmor mode/context/profile + audit/log correlation + key/certificate/SAN/EKU/chain/trust store/SNI + original workload result.

Interpretation rule. - SELinux installed or enabled ≠ enforcing with the expected loaded policy.

  • An AVC denial identifies an SELinux decision ≠ malicious intent or evidence that SELinux is the root cause of the overall incident.

Mechanics

Follow the path in order: identity/group resolution → Unix mode/ACL/capability → mount/sandbox constraint → SELinux/AppArmor policy → credential/TLS trust → protected operation.

Important negative cases include UID/GID mismatch, stale group membership, ACL/mode conflict, missing capability, noexec/readonly mount, SELinux denial, AppArmor denial, expired/untrusted certificate or secret exposure.

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. SELinux is resolved when mode, policy and relevant contexts are confirmed, the first incorrect label/policy boundary is corrected minimally, and the original workload passes without broadening policy unnecessarily.

Model. chmod 777 cannot override LSM or read-only mount policy. Disabling SELinux/AppArmor to make an error disappear only localizes a policy boundary and can hide the real label/profile defect. PAM success does not show sudo, filesystem or application authorization. Fail2ban acts on observed authentication patterns and network banning; it does not fix authentication policy. Security controls should remain explicit layers rather than a single “permission denied” bucket.

ReferenceConfiguration & state2 sections · depth on demand

Configuration, persistence and lifecycle

Configuration intent and lifecycle. Harden one control with a known access/recovery path and preserve the policy source of truth. PAM stack order/control flags matter; sudo/SSH hardening can lock out administration; SELinux policy should normally be fixed through correct labels/booleans/policy rather than permanent disablement; AppArmor profiles should move from complain to enforce only after reviewing legitimate workload behavior. Audit rules need bounded scope to avoid volume/resource problems.

Distribution/platform context. SELinux root owns operational MAC diagnosis and configuration; Security → SELinux is the architecture-level bridge.

Lifecycle

Linux configuration is semantic even when a command returns zero. systemd generators and drop-ins, package scripts, udev, mount helpers, netlink, resolver caches, namespaces, SELinux/AppArmor policy and kernel drivers can make runtime state differ from the file or command that appears to own it.

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. 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
SELinuxsecurity enhanced linuxselinux mac
Embedded reference data

Quick lookup tables

SELinux operational reference

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

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateSELinux is the dedicated operational reference for label-based mandatory access control: runtime mode, loaded policy, process domains, object types/labels, transitions and AVC evidence are traced to the application operation.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 + object label → DAC/capabilities → SELinux policy/boolean/transition → AVC allow/deny → audit → workload → persistent label/policy remediationTrace requested/configured state through effective state to the observed workload result.
Failure boundarySELinux closes when mode, policy and relevant contexts are proven, the first incorrect label/policy boundary is corrected minimally, and the original workload passes without broadening policy unnecessarily.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 + object label → DAC/capabilities → SELinux policy/boolean/transition → AVC allow/deny → audit → workload → persistent label/policy remediationUse 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. SELinux closes when mode, policy and relevant contexts are proven, the first incorrect label/policy boundary is corrected minimally, and the original workload passes without broadening policy unnecessarily.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.

SELinux · operational reference

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

Reference boundarySELinux
Topic pathSELinux
Runtime stateSELinux is the dedicated operational reference for label-based mandatory access control: runtime mode, loaded policy, process domains, object types/labels, transitions and AVC evidence are traced to the application operation.
Fast checks- Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for SELinux. - 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 + object label → DAC/capabilities → SELinux policy/boolean/transition → AVC allow/deny → audit → workload → persistent label/policy remediation Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary.
Failure boundarySELinux closes when mode, policy and relevant contexts are proven, the first incorrect label/policy boundary is corrected minimally, and the original workload passes without broadening policy unnecessarily. 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?