Join our Newsletter — 33% off our NHI Course
Home› Guides› SELinux Guide: Fix Denials Properly and Keep Enforcing…
Guide Endpoint Security

SELinux Guide: Fix Denials Properly and Keep Enforcing Mode On

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 15 min read
On this page

SELinux is the mandatory access control layer that contains a compromised service on Red Hat family systems, and the most common response to its first denial is to switch it off. This guide explains how SELinux makes decisions, how to read and fix denials without weakening policy, how to confine administrators and service accounts, and how to monitor that enforcement stays on. It covers RHEL, CentOS Stream, Rocky Linux, AlmaLinux and Fedora with the targeted policy, with commands taken from the Red Hat Enterprise Linux 9 documentation. It is written for Linux administrators, platform engineers and security teams who own server baselines. For the wider host baseline see the Linux Server Hardening Guide, and for the theory behind label based access control see the Reference Monitors and Mandatory Access Control Guide.

This is an independent guide from NHI Mgmt Group, based on Red Hat's public documentation as of November 2026. It is not sponsored or reviewed by Red Hat. Product features change, so confirm settings against Red Hat's current documentation.

Key takeaways

  • Permissive is the debugging mode, disabled is not. Red Hat recommends permissive mode for production troubleshooting; disabling skips labelling, so re-enabling later needs a full relabel and a careful reboot.
  • Most denials are labelling or configuration problems. Check file contexts, booleans and port labels before writing any policy; Red Hat explicitly says not to reach for audit2allow first.
  • Per-domain permissive beats global permissive. semanage permissive -a httpd_t relaxes one service while the rest of the host stays enforced.
  • Users are unconfined by default. The __default__ login maps to unconfined_u; mapping administrators to staff_u with a sudo role transition puts real limits on interactive root.
  • AVC records are a detection signal. Sudden denials from a web or database domain, or a host leaving enforcing mode, are worth alerting on, not just ticketing.

How SELinux decides access: contexts, types and policy

SELinux is a Linux Security Module (LSM). The kernel LSM documentation states that the capabilities module always runs first, any number of minor modules (such as Yama) follow, and at most one major module such as SELinux is active; the active list is visible in /sys/kernel/security/lsm. SELinux checks run after normal discretionary permissions, so a file that is world readable can still be denied to a process whose domain has no rule for it.

Every process and object carries a context with four fields: user, role, type and level, written as user:role:type:level (for example system_u:system_r:httpd_t:s0). The type is the field that matters day to day. Policy is default deny: a process type (a domain) may only touch object types an allow rule names. Apache runs as httpd_t, its content is labelled httpd_sys_content_t under /var/www/html, and it may bind only to ports labelled http_port_t. If Apache is exploited, the attacker inherits httpd_t, not the full rights of the account.

ConceptWhat it isWhere you see it
ModeEnforcing, permissive (log only) or disabledgetenforce, sestatus, SELINUX= in /etc/selinux/config
Policy typetargeted (default, confines selected services) or mlsSELINUXTYPE= in /etc/selinux/config
DomainThe type of a running process, for example httpd_t, mysqld_tps -eZ
File contextLabel on a file, for example httpd_sys_content_t, mysqld_db_tls -Z, matchpathcon -V
BooleanSwitch that turns optional policy rules on or offgetsebool -a, semanage boolean -l
Port labelType assigned to a TCP or UDP portsemanage port -l
Level and categoriesMLS sensitivity and MCS categories such as s0:c270,c963, used to keep containers apartps -efZ on container processes

Unconfined is not the same as off. A daemon started from a binary that has no policy runs as unconfined_service_t. It is labelled and logged, but it has broad rights. On a hardened host the number of processes in unconfined domains should be small and known.

Modes and how to change them safely

  • Runtime switch: setenforce 0 and setenforce 1 change the mode until reboot only. Use it for a minutes long test, not as a fix.
  • Persistent mode: edit SELINUX= in /etc/selinux/config and reboot. In permissive mode each distinct AVC is logged once, so you collect the full set of denials a workload would hit.
  • Disabling on RHEL 9: the documented method is the kernel parameter selinux=0, set with grubby --update-kernel ALL --args selinux=0. With it, the kernel loads no SELinux infrastructure and init touches /.autorelabel so the next enabled boot relabels the file system. Red Hat advises against production use.
  • Boot overrides: enforcing=0 boots permissive; autorelabel=1 forces a relabel. Both are recovery tools and should be absent from the steady state kernel command line.

Confined users and privileged access

The targeted policy confines services well, but by default people are not confined. semanage login -l shows that __default__ maps every unmapped Linux user to unconfined_u at range s0-s0:c0.c1023. A compromised admin session therefore has the full rights of root. Mapping users to confined SELinux users changes that.

SELinux userDefault rolesu / sudoTypical use
unconfined_uunconfined_rAllowedDefault for all users; avoid for production admins
user_uuser_rNot allowedOrdinary users and application operators who never need root
staff_ustaff_r (can enter sysadm_r)sudo onlyAdministrators: log in confined, elevate through sudo
sysadm_usysadm_rAllowedDedicated admin accounts; SSH login governed by ssh_sysadm_login
guest_u, xguest_uguest_r, xguest_rNot allowedKiosk or restricted shells; no networking for guest_r
system_usystem_rNot applicableSystem processes only; Red Hat says never assign it to a Linux user
  • Change the default: semanage login -m -s user_u -r s0 __default__ maps all unmapped users to user_u; Red Hat documents this as a way to meet a STIG requirement. New sessions then run as user_u:user_r:user_t:s0, which cannot run setuid tools such as sudo.
  • Map admins explicitly: useradd -Z staff_u <user> or usermod -G wheel -Z sysadm_u <user>, then restorecon -R -F -v /home/<user>.
  • Role transition through sudo: a rule in /etc/sudoers.d/ with ROLE=sysadm_r and TYPE=sysadm_t moves a staff_u:staff_r:staff_t session to staff_u:sysadm_r:sysadm_t only for the elevated command. Pair this with the controls in the sudo and sudoers Security Guide.
  • Execution from writable paths: the *_exec_content booleans control whether a role can run content from home and /tmp. Red Hat notes guest_exec_content and xguest_exec_content should be set off.

Decision guidance: small teams with a handful of servers often start by confining only non-admin users to user_u, which is low risk. Larger estates with jump hosts and PAM tooling gain more from staff_u plus sudo transitions for admins, because it limits what a stolen admin session can do outside an approved command. Test confined admin roles on a pilot group first: backup agents, configuration management and monitoring scripts run through sudo may need extra roles such as logadm_r or dbadm_r.

Services, containers and custom policy modules

Service accounts are where SELinux earns its keep. A daemon running as a dedicated Linux account with a confined domain is limited twice: by its UID and by its type. When third party agents, databases or in-house daemons run as unconfined_service_t, that second layer is missing. The account side of this is covered in the Linux Service Accounts and Keytab Management Guide.

Fix order for a denial

  1. Labels: if content moved to a non default path, add a rule and apply it: semanage fcontext -a -t httpd_sys_content_t "/srv/myweb(/.*)?", then restorecon -R -v /srv/myweb. semanage fcontext alone changes nothing on disk; chcon changes do not survive a relabel.
  2. Booleans: look for an existing switch before writing rules, for example setsebool -P httpd_can_network_connect_db on. Without -P the change is lost at reboot.
  3. Ports: a service on a non standard port needs the port labelled: semanage port -a -t http_port_t -p tcp 9876.
  4. Policy bug or genuinely new behaviour: only now generate rules. Red Hat advises using rules it provides (Known Issues, Solutions) in a small .cil module with a local_ prefix, installed with semodule -i and removed with semodule -r.

Writing policy for your own daemon

For in-house services, sepolicy generate --init /usr/local/bin/mydaemon produces a type enforcement file (.te), interface file (.if), file contexts (.fc), a spec file and a build script. After loading, ps -efZ should show the process in its own mydaemon_t domain rather than unconfined_service_t. Run that domain permissive with semanage permissive -a mydaemon_t while you exercise the service, review ausearch -m AVC -ts recent | audit2allow -R output, prefer interface macros (for example logging_write_generic_logs(mydaemon_t)) over raw allow rules, then remove the permissive flag with semanage permissive -d mydaemon_t.

Review every generated rule. audit2allow writes whatever the denial needs. A rule letting a web domain write shadow_t or execute tmp_t is a request to approve the attack, not a fix. Keep local modules in version control and review them like code.

Containers

Podman containers run in a generic container domain with unique MCS categories per container (visible as s0:cNNN,cNNN in ps -efZ), which stops one container reading another's files even when both run as the same type. Red Hat notes the generic domain can be too strict or too loose for a given workload; udica builds a per-container policy from podman inspect output, and the container is started with --security-opt label=type:my_container.process. Never mount host paths with relabelling options onto system directories such as /home or /usr. See the Container Runtime Security Guide.

Logging and detection

SELinux denials are written by auditd to /var/log/audit/audit.log as AVC records (kernel message type 1400). The Red Hat search filter is ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent; if auditd is not running, use dmesg | grep -i -e type=1300 -e type=1400. The key fields are scontext (the process), tcontext (the target), tclass (file, tcp_socket, process) and the permission in braces. sealert -l "*" from setroubleshoot-server explains each denial in plain language, and journalctl -t setroubleshoot shows its summaries. Some denials are hidden by dontaudit rules; semodule -DB disables them temporarily and semodule -B restores them. Shipping audit logs is covered in the Linux Logging and auditd for Defenders Guide.

SignalWhy it mattersSuggested handling
AVC from httpd_t, mysqld_t or another internet facing domain trying to execute, connect out or read shadow_tPost exploitation behaviour blocked by policy (ATT&CK T1190 followed by attempts at T1068)High priority alert; investigate the service, not the policy
Mode change: MAC_STATUS audit record, setenforce 0 in shell history, selinux=0 or enforcing=0 on the kernel command lineDefence tampering (ATT&CK T1685 Disable or Modify Tools)Alert and require a change ticket
MAC_POLICY_LOAD, new modules in semodule -lfull, boolean changesPolicy weakened, legitimately or notCompare to an approved module and boolean list
Spike in AVCs after a deploymentLabelling or path change in the releaseRoute to the owning team; fix labels in the package or automation
Container process with an unexpected type or no categoriesContainer run privileged or with labelling disabled, raising escape risk (T1611)Block at admission or in the run configuration

Metrics that show it is working

  • Enforcing coverage: percentage of Linux hosts where getenforce returns Enforcing (target 100% outside documented exceptions).
  • Unconfined services: count of processes in unconfined_service_t per host, trending down.
  • Permissive domains: number of domains in semanage permissive -l, each with an owner and expiry date.
  • Local modules: count of local policy modules and the share reviewed in the last 12 months.
  • Time to resolve denials: median days from first AVC on a new release to a label, boolean or reviewed module fix.
  • Confined admins: percentage of admin accounts mapped to staff_u or sysadm_u rather than unconfined_u.

Hardening baseline

Rollout plan

  1. Inventory: collect sestatus, semanage permissive -l, semodule -lfull | grep local_, semanage login -l and the kernel command line from every host. Group hosts into enforcing, permissive and disabled.
  2. Disabled hosts first move to permissive, not enforcing: remove selinux=0 with grubby --update-kernel ALL --remove-args selinux=0, set SELINUX=permissive, run fixfiles -F onboot and reboot. Red Hat warns to confirm the system boots in permissive mode before relabelling.
  3. Collect denials for a full business cycle: include month end jobs, backups and patching. Fix with labels, booleans and port types in configuration management, not by hand.
  4. Pilot ring to enforcing: switch a small ring, watch AVCs and service health for a week, then widen. Keep any stubborn service in a per-domain permissive exception with an owner and end date.
  5. Confine people: map __default__ to user_u and admins to staff_u with sudo role transitions on a pilot group before estate wide rollout.
  6. Rollback: for a single service, semanage permissive -a <domain>; for a host, setenforce 0 immediately and SELINUX=permissive persistently. Do not roll back by disabling, because recovery then costs a relabel.

Framework mapping

FrameworkReferenceHow SELinux supports it
NIST SP 800-53 Rev. 5AC-3(3) Mandatory Access Control; AC-6 Least Privilege; SC-39 Process IsolationType enforcement confines domains regardless of the account's rights
NIST SP 800-53 Rev. 5CM-6 Configuration Settings; CM-7 Least Functionality; AU-12 Audit Record GenerationMode, booleans and modules as baseline settings; AVC records as audit events
NIST CSF 2.0PR.PS-01, PR.AA-05, DE.CM-09Configuration management, enforced access permissions, monitoring of runtime environments
CIS Controls v8.1Control 4 Secure Configuration of Enterprise Assets and SoftwareCIS Benchmarks for RHEL family systems check SELinux is installed, not disabled and enforcing
ISO/IEC 27001:2022Annex A 8.9 Configuration management; 8.2 Privileged access rightsDocumented MAC baseline and confined admin roles
MITRE ATT&CK v20T1190, T1068, T1611, T1685Limits post exploitation reach; mode changes are a tampering signal

Compliance profiles for CIS and STIG can be scanned automatically; see the OpenSCAP and Linux Compliance Scanning Guide and the Red Hat Enterprise Linux Security Hardening Guide.

Common misconfigurations

  • Disabling to fix one service: a single denial on install leads to SELINUX=disabled in a golden image, and every later host inherits it. Use per-domain permissive and fix the label.
  • Blind audit2allow: piping all denials into a module and loading it, which can grant a compromised domain exactly the access policy just stopped. Review each rule against the fix order above.
  • chcon instead of semanage fcontext: labels look right until the next relabel or restorecon run reverts them, and the outage returns months later.
  • Booleans set without -P: the fix works until the next patch reboot. Manage booleans in configuration management.
  • Permanent permissive exceptions: semanage permissive -a used in an incident and never removed. Review the list monthly.
  • Vendor agents left unconfined: monitoring, backup and security agents installed under /opt run as unconfined_service_t with root. Ask vendors for SELinux policy modules or confine them yourself, and treat their credentials as privileged non-human identities, as the Service Account Security Guide describes.

Practitioner checklist

  • Confirm every RHEL family host reports Enforcing with the targeted policy, and alert on any change.
  • Remove selinux=0, enforcing=0 and autorelabel=1 from steady state kernel command lines.
  • Fix denials in order: file contexts, booleans, port labels, then reviewed local modules.
  • Use semanage fcontext plus restorecon, never chcon, and set booleans with -P from configuration management.
  • Keep per-domain permissive exceptions on a register with owner and expiry.
  • Map __default__ to user_u and admins to staff_u with sudo role transitions.
  • Give in-house daemons their own domain with sepolicy generate; keep local modules in version control.
  • Ship AVC, MAC_STATUS and MAC_POLICY_LOAD records to the SIEM and alert on internet facing domains.
  • Run containers with labelling enabled and use udica where the generic domain is wrong for the workload.

Standards and references

Related NHI Mgmt Group resources: Linux Server Hardening Guide · AppArmor Guide · Linux Kernel Hardening and sysctl Guide · Linux Privilege Escalation Techniques Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 8 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.