ITNuvoAkademiya
Academy homePackagesPlaylistsToolsSubnet calculatorSearchGlossary
CiscoCCNA · CCNA: networking fundamentals1. Introduction2. Network Fundamentals3. Network Access4. IP Connectivity5. IP Services6. IPv67. Security Fundamentals8. AutomationCCNP: Enterprise networks · coming soon
LinuxLinux: system administrator üçün · Linux for system administrators1. Getting to know Linux2. Working with text3. Users and permissions4. Processes and packages5. Inside the system6. Monitoring and logs7. NetworkingRed Hat Enterprise Linux · Red Hat Enterprise Linux: from beginner to advanced1. Getting started2. Packages3. Users and permissions4. SELinux5. Services6. Storage7. Networking8. Building services9. Boot and recovery10. DevOps11. Security and monitoring
FortinetFortiGate Administrator · FortiGate Administrator: from first login to ZTNA1. Getting to know FortiGate2. Routing, policy and NAT3. Security profiles4. Users and logs5. Resilience, SD-WAN and automation6. VDOM7. VPN and ZTNA8. Proxy9. DMZ
MonitoringZabbix · Zabbix: from installation to alerts1. Introduction2. Installation and the database3. Basics: groups, templates, users4. Connecting devices5. Alerts, Grafana and the API
VirtualizationProxmox VE · coming soonVMware ESXi · coming soon
My account / Sign in
AZENRU
← itnuvo.com

What SELinux is: enforcing, permissive, getenforce

Lesson 4.18 minIntermediateDecember 1, 2026
Open

This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.

Key points

  • Standard permissions are DAC (the owner decides); SELinux is MAC (the system policy decides) and is checked after DAC.
  • Every process and file carries a context: user:role:type:level; decisions are based on the type (httpd_t, httpd_sys_content_t).
  • Modes: enforcing (blocks and logs), permissive (only logs), disabled.
  • getenforce, sestatus — check; setenforce 0/1 — temporary; permanent — /etc/selinux/config.
  • When there is a problem, do not turn SELinux off: diagnose with permissive, then fix with a context, boolean or port.

Why SELinux

Classic Linux permissions are called DAC (Discretionary Access Control): a file's owner decides who gets what, and root can do everything. The problem: if nginx or httpd is compromised, the attacker can do everything that process can do.

SELinux adds MAC (Mandatory Access Control): for each process the system policy states exactly which types of files, ports and processes it may touch. A file's owner cannot change the policy.

ScenarioDAC onlyDAC + SELinux
A compromised httpd tries to read /etc/shadowDepends on permissionsBlocked: httpd_t cannot read shadow_t
httpd tries to connect to port 4444 (a backdoor)AllowedBlocked: the port is not http_port_t
httpd serves a file from a user's home directoryYes, if the mode is 755Blocked: user_home_t

The order of checks: DAC first, then SELinux. Both must allow it.

The context: a label on everything

srv-web01
[ali@srv-web01 ~]$ id -Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[ali@srv-web01 ~]$ ps -eZ | grep -E "httpd|sshd" | head -n 2
system_u:system_r:httpd_t:s0        1588 ?        00:00:00 httpd
system_u:system_r:sshd_t:s0-s0:c0.c1023 1032 ? 00:00:00 sshd
[ali@srv-web01 ~]$ ls -Z /var/www/html/index.html /etc/shadow
unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html
         system_u:object_r:shadow_t:s0 /etc/shadow

A context has four parts: user:role:type:level.

PartExampleRole
usersystem_uSELinux user
roleobject_rRole
typehttpd_t, httpd_sys_content_tThe main decision is based on this
levels0MLS/MCS level

In daily work you deal only with the type. The policy consists of rules like "a httpd_t process may read httpd_sys_content_t files". This is the targeted policy — RHEL uses it by default: network services are confined, while user processes (unconfined_t) are barely restricted.

Modes

ModeWhat it doesWhen
EnforcingBlocks what is forbidden and logs itAlways — the production standard
PermissiveBlocks nothing, only logsBriefly, for diagnosis
DisabledCompletely off, files are not labelledNot recommended
srv-web01
[ali@srv-web01 ~]$ getenforce
Enforcing
[ali@srv-web01 ~]$ sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      33

Changing the mode

srv-web01
[ali@srv-web01 ~]$ sudo setenforce 0
[ali@srv-web01 ~]$ getenforce
Permissive
[ali@srv-web01 ~]$ sudo setenforce 1
[ali@srv-web01 ~]$ grep ^SELINUX= /etc/selinux/config
SELINUX=enforcing
HowEffect
setenforce 0 / setenforce 1Permissive / enforcing — until reboot
SELINUX= in /etc/selinux/configPermanent, applied at boot
Kernel parameter enforcing=0For one boot (in recovery situations)
semanage permissive -a httpd_tMake only one process type permissive

Important: moving from disabled to enforcing requires relabelling the whole file system (touch /.autorelabel and reboot) — it takes a long time and leads to mistakes. So never set SELinux to disabled; if needed, a temporary permissive is enough.

The "turn SELinux off" advice

The first step of many guides on the internet is setenforce 0. That is like leaving the door open: the problem is "solved", but the protection is gone too. The right approach:

  1. Reproduce the problem and confirm SELinux is the cause (ausearch -m AVC -ts recent).
  2. Identify the cause: a wrong context (4.2), a disabled boolean (4.3), a non-standard port (4.3).
  3. Make a precise fix and test in enforcing mode.

The remaining lessons of the unit solve these three causes one by one.

Lab: get to know SELinux

In the Red Hat simulator, on srv-web01:

  1. Check the mode:
srv-web01
[ali@srv-web01 ~]$ getenforce
Enforcing
[ali@srv-web01 ~]$ sestatus | grep -E "mode|policy name"
  1. Look at the contexts of processes and files:
srv-web01
[ali@srv-web01 ~]$ ps -eZ | grep httpd
[ali@srv-web01 ~]$ ls -Z /var/www/html/
[ali@srv-web01 ~]$ ls -Zd /home/ali
  1. Write down the type of three files: /var/www/html (httpd_sys_content_t), /home/ali (user_home_dir_t), /etc/shadow (shadow_t).
  2. (On your own VM) setenforce 0, getenforce, then be sure to run setenforce 1.

Check: getenforce shows Enforcing at the end.

Check yourself

5 questions · answers are shown instantly · 3 correct answers complete the lesson

1What kind of access control is SELinux?

A file's owner cannot change the policy.

2Which part of the context are SELinux decisions based on?

For example, a httpd_t process may read httpd_sys_content_t files.

3What happens in permissive mode?

Useful for diagnosis.

4Which file is edited to change the SELinux mode permanently?

setenforce only lasts until reboot.

5Why is disabling SELinux not recommended?

If needed, a temporary permissive is enough.
Was this lesson useful?

Comments

Sign in to comment.