Permissions and owners
The getenforce command
Shows the SELinux mode: Enforcing, Permissive or Disabled.
Copy-ready examples
$ getenforcecurrent SELinux mode.Example output
Enforcing
$ if [ "$(getenforce)" = Enforcing ]; then echo 'SELinux bloquea'; fia script that acts only when the mode is Enforcing.Example output
SELinux bloquea
$ sudo setenforce 0 && getenforceswitches to Permissive and checks the result.Example output
Permissive
You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| bash: getenforce: command not found | The SELinux utilities are not installed. Fedora and RHEL ship them; Debian and Ubuntu do not have them by default. | If your distribution uses SELinux, install its utilities. If it uses AppArmor, this command does not apply to you. |
| getenforce: is_selinux_enabled() failed | The check for whether SELinux is enabled failed. The program exits with code 2 and prints no mode. | Check the boot parameters: selinux=0 disables SELinux, according to selinux(8). |
Typical mistakes
- Permissive does not block: it only logs what the policy would reject. Enforcing does block.
- Disabled is not the same as Permissive: with Disabled no SELinux policy is applied at all.
- The mode you have after boot is set by SELINUX= in /etc/selinux/config. According to selinux(8), that file controls whether SELinux is active and in which mode.
Differences from similar commands
- setenforce: changes the mode. getenforce only reads it.
selinuxenabled: is the related utility of the same family that tells whether SELinux is enabled; the getenforce and setenforce pages cite it.
Related commands
FAQ
Why does it show Disabled?
The usual cause is SELINUX=disabled in /etc/selinux/config, or the selinux=0 boot parameter. selinux(8) marks the first option as deprecated and recommends the second.
Enforcing or Permissive?
Enforcing blocks what the policy does not allow. Permissive allows it and logs it, so it helps debug a denial without cutting the service.
Can getenforce change the mode?
No, it only shows it. To change it on the fly, use setenforce.
How do I know if SELinux is active?
If getenforce answers Enforcing or Permissive, SELinux is active. With Disabled no policy is applied, even if the tools are installed.
More Permissions and owners commands
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course