Use SELinux booleans to grant controlled exceptions for services rather than turning off SELinux.
Quick overview
- SELinux booleans toggle parts of the policy at runtime.
- Runtime-only changes apply immediately but are lost at reboot unless persisted.
- Two common tools:
setsebool— change runtime state (optionally persist with-P).semanage boolean— view and change persistent settings with descriptions.
Checking SELinux mode
Confirm SELinux is running and in enforcing mode:Listing all booleans
List all SELinux booleans and their current runtime state withgetsebool -a:
grep:
Changing booleans with setsebool
To change a boolean at runtime, usesetsebool followed by the boolean name and on or off. By default, this affects only the running system and will be lost after a reboot.
Examples (runtime-only):
setsebool, add the -P (uppercase P) option:
Remember:
setsebool without -P changes only the current runtime state. Use -P to persist changes across reboots.Inspecting booleans and descriptions with semanage
If you prefer a more descriptive listing that includes a short description and both runtime and persistent states, use:semanage output, the first value in parentheses is the runtime state and the second is the persistent state (what will be applied after a reboot). You can filter semanage output the same way as getsebool:
Changing booleans persistently with semanage
To modify a boolean persistently usingsemanage, use the -m option together with --on or --off. For example, to enable httpd_enable_homedirs persistently:
semanage boolean -l | grep httpd_enable_homedirs or getsebool -a | grep httpd_enable_homedirs to confirm both runtime and persistent states.
Common commands (cheatsheet)
Summary
- SELinux booleans let you toggle policy behavior without editing policies.
- Use
getsebool -ato list runtime boolean states andgetsebool -a | grep <term>to filter. - Use
setsebool <boolean> on|offto change the runtime state; add-Pto persist withsetsebool. - Use
semanage boolean -lto list booleans with descriptions and both runtime and persistent values. - Use
semanage boolean -m --on|--off <boolean>to change the persistent state viasemanage.