Use it when SELinux blocks a service, or when deploying a service with custom paths or ports on RHEL.
SELinux
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.
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>.
process domain and file type → policy rule checked → allowed or AVC denial logged
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
Operational reference
Fast context before you go deeper.
getenforcePrimary Commands
Configuration and operational commands for this Topic.
getenforceReferenceReturn 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.
sestatusReferenceSummarize 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.
restoreconReferenceReset 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.
semanageReferenceManage 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.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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 0as 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 · 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.
Subtopics
Go one level deeper into this subject.
SELinux Enforcing mode applies loaded policy decisions so denied operations are blocked and normally audited, making runtime mode and the exact AVC/workload correlation central evidence.
Subtopic PermissiveSELinux Permissive mode evaluates policy and records denials that would have been enforced, but generally allows the operation, making it useful for controlled diagnosis rather than production enforcement.
Subtopic DisabledSELinux Disabled mode means SELinux policy enforcement is not active for the running system and may require boot-time configuration/reboot to change, so absence of AVCs cannot be used as evidence of correct policy.
Subtopic ContextsSELinux 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.
Subtopic LabelsSELinux Labels covers how filesystem/object labels are assigned, restored and persisted through policy file-context mappings, relabel operations and package/service expectations.
Subtopic SELinux TroubleshootingSELinux Troubleshooting isolates whether an observed failure is caused by mode, context, label mapping, boolean, transition or policy by correlating AVC records with the exact denied operation before changing policy.
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.
getenforce / sestatus— mode and policyls -Z <path>— file contextps -eZ | grep <proc>— process contextausearch -m AVC -ts recent— recent denialssemanage 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.
| Concept | Meaning |
|---|---|
| Context | user:role:type:level, e.g. system_u:object_r:httpd_sys_content_t:s0 |
| Type enforcement | Rules like "httpd_t may read httpd_sys_content_t" |
| Modes | Enforcing (blocks and logs), Permissive (logs only), Disabled |
| Booleans | Switches for optional behaviour, e.g. httpd_can_network_connect |
| AVC denial | Logged 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 domainhttpd_tmay read files labelledhttpd_sys_content_t. - Denials: logged to
/var/log/audit/audit.logastype=AVCmessages. - Modes:
setenforceswitches between enforcing and permissive until the next reboot, andgetenforceshows 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
| Step | Command | Looking for |
|---|---|---|
| 1. Confirm it's SELinux | ausearch -m AVC -ts recent | Denials at the time of the failure |
| 2. Read the denial | ausearch -m AVC -ts recent -i | The source type, the target type and class, the permission |
| 3. Get an explanation | sealert -a /var/log/audit/audit.log (setroubleshoot) | Suggested fixes |
| 4. Choose the fix | — | See the table below |
| 5. Verify | Repeat the action; check for new AVCs | — |
Choosing the right fix
| Cause | Fix |
|---|---|
| Files in a non-standard location | semanage fcontext -a -t <type> '<path>(/.*)?' + restorecon -Rv <path> |
| Labels lost after copying or restoring | restorecon -Rv <path> |
| A service on a non-standard port | semanage 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 need | A local policy module from audit2allow (review it first) |
| Testing only | setenforce 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.
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.
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
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%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.
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.
Quick lookup tables
SELinux operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for SELinux.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | 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. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin 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 chain | process domain + object label → DAC/capabilities → SELinux policy/boolean/transition → AVC allow/deny → audit → workload → persistent label/policy remediation | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | 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. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated 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 remediation | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It 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 check | Continue 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 boundary | SELinux |
|---|---|
| Topic path | SELinux |
| Runtime state | 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. |
| 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 chain | process 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 boundary | 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. Boundary chain: process credentials/namespace → path/mount lookup → DAC/ACL/LSM → filesystem metadata → block/device/backend → completion/read-back. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |