Mode and status
getenforce
Show the current mode
sestatus
Full status: mode, config, policy
Current mode and Mode from config file can differ.
setenforce 0
Switch to permissive until reboot
Denials are logged but not enforced. Use it to test, not as a
fix.
setenforce 1
Switch back to enforcing
semanage permissive -a <domain>
Make one domain permissive
E.g. httpd_t: the rest of the system stays enforcing.
semanage permissive -d <domain>
Enforce that domain again
semanage permissive -l
List permissive domains
SELINUX=enforcing
Boot mode in /etc/selinux/config
Or permissive. Keep SELINUXTYPE=targeted; reboot to apply.
grubby --update-kernel ALL --args enforcing=0
Boot into permissive via kernel arg
grubby --update-kernel ALL --args selinux=0
Disable SELinux entirely (RHEL 9+)
Last resort. Turning it back on needs a full relabel.
Modes
| Mode |
Effect |
enforcing |
denies and logs |
permissive |
logs only, allows |
disabled |
no checks, no labels kept |
File labels
semanage fcontext -a -t <type>
'<path>(/.*)?'
Add a persistent label rule
Changes the policy only; run restorecon to apply it.
restorecon -Rv <path>
Relabel files to match the rules
restorecon -Rnv <path>
Dry run: show what would change
chcon -t <type> <file>
Change a label temporarily
Lost on the next restorecon or relabel; use for tests only.
chcon --reference=<ref> <file>
Copy another file's label
semanage fcontext -a -e <src> <dst>
Label dst like src (equivalence)
semanage fcontext -l -C
List your local label rules
semanage fcontext -l | grep <path>
Find the rule for a path
semanage fcontext -d '<path>(/.*)?'
Delete a local label rule
chcon or semanage?
| Tool |
After relabel |
chcon |
label lost: tests only |
semanage fcontext |
label kept: the real fix |
Denials
ausearch -m AVC -ts recent
Show denials of the last 10 minutes
Other -ts words: today, boot, this-week.
ausearch -m AVC -c <comm> -i
Denials of one program, readable
ausearch -m AVC -ts recent | audit2why
Explain why access was denied
sealert -l "*"
Analysis with suggested fixes
Needs setroubleshoot-server.
journalctl -t setroubleshoot
setroubleshoot alerts in the journal
semodule -DB
Rebuild without dontaudit rules
Reveals silenced denials; restore with semodule -B.
semodule -B
Rebuild policy, dontaudit back on