SELinux and AppArmor in Linux: mandatory access control
Updated November 1, 2026
SELinux and AppArmor are an extra layer of protection: they limit what a process is allowed to do, on top of the usual rwx permissions.
Common cases
getenforce # SELinux mode: Enforcing or Permissive
sestatus # detailed SELinux status
sudo setenforce 0 # switch to Permissive for now
ls -Z file # a file's SELinux label
aa-status # AppArmor profile status (Ubuntu)Sample output
$ getenforce
Disabled
$ sestatus
SELinux status: disabled
$ aa-status
apparmor not present.
$ ls -Z /etc/hostname
? /etc/hostname
$ id -Z
id: --context (-Z) works only on an SELinux-enabled kernelHow it works: mandatory control on top of the usual
The usual
rwxpermissions are 'discretionary' control: the file's owner decides who may do what, and root may do anything. SELinux and AppArmor add 'mandatory' control: an administrator sets the rules through a policy, and even a root process cannot step outside its profile. The point is to contain a compromised service: even after taking over a web server, an attacker cannot read what the profile does not allow. SELinux (RHEL, Fedora) labels everything, while AppArmor (Ubuntu, SUSE) ties rules to paths. If something is oddly denied with correct permissions, check whether the policy is blocking it.
Common mistakes
'Command not found' does not mean nothing is guarding the machine. On a plain Ubuntu getenforce answers bash: getenforce: command not found, because it ships in the selinux-utils package, which is not installed. Ubuntu itself runs AppArmor, and the question for AppArmor is aa-status from the apparmor package. Each tool knows only its own system: getenforce says nothing about AppArmor, and aa-status says nothing about SELinux.
SELinux has three states, and Disabled differs from Permissive more than it looks. Permissive means the policy is loaded, decisions are made and written to the log, and nothing is blocked; that is how you find out in advance what would break in production. Disabled means there is no policy at all. You cannot leave Disabled with a command: setenforce 0 answers setenforce: SELinux is disabled, and turning it on takes an edit in /etc/selinux/config plus a reboot.
On a machine without SELinux ls -Z prints no label but ? /etc/hostname, and id -Z answers id: --context (-Z) works only on an SELinux-enabled kernel. The question mark means 'this kernel has no labels at all', not 'this file has a broken label'. The difference costs time: people see ? and start repairing labels with chcon and restorecon on a system where SELinux is not running, then wonder why nothing changes.
In the book
This topic is covered in full in the chapter Deep security.