What Is SELinux, and How Does It Work? (Explained Clearly) - Security-Enhanced Linux
CompTIA Security+ SY0-801: Cybersecurity Fundamentals
What is SELinux? Learn how labels and policies enforce least privilege, and use AVC audit logs to troubleshoot access denials without disabling SELinux.
👉 Master your Security+ skills with Pluralsight here: Pluralsight
You’ll learn what SELinux (Security-Enhanced Linux) is and how it uses mandatory access control, security labels, and policies to enforce least privilege. See how to use AVC audit logs to troubleshoot Linux “permission denied” errors without disabling SELinux.
Chapters:
0:00 Intro
0:14 What is SELinux, and why does Linux need it?
1:04 How does SELinux decide what to allow?
1:49 What’s the difference between enforcing, permissive, and disabled?
2:42 How do you troubleshoot an SELinux denial?
3:50 Outro
Affiliate notice: Some links may earn a commission. Thanks for your support.
- SELinux adds mandatory access control to Linux. It can block actions that ordinary file permissions allow, even for a confined process running as
root. - Labels, not file paths, drive type enforcement. Policy checks the process domain, target type, object class, and requested action, so Apache can be allowed to read a file without being allowed to write it.
- Check the mode with
getenforce. Enforcing blocks policy violations; permissive can log them without blocking; disabled neither checks policy nor logs would-be denials. - Diagnose
Permission deniedbefore changing policy. Check ordinary permissions first, then inspect labels and look for a matching AVC denial. A missing AVC entry doesn’t rule out SELinux. See Red Hat’s troubleshooting guide. - Fix mislabeled files without weakening enforcement. Use
semanage fcontextto record the expected label andrestoreconto apply it. Don’t generate anaudit2allowrule just because an operation was denied. - 👉 Put your cybersecurity knowledge into practice with Pluralsight: build skills in guided labs, get feedback, and focus your certification prep with assessments and practice exams.
SELinux (Security-Enhanced Linux) is a Linux kernel security feature that controls what processes can do. It can stop Apache from reading a file even when the file’s owner, group, and permission bits allow the read. That extra check helps contain buggy or compromised services, but it also explains why Linux can return Permission denied when the usual permissions look right.
What Is SELinux, and Why Does Linux Use It?
SELinux implements mandatory access control (MAC) through the Linux Security Modules framework. A system-wide policy sets limits that a file owner can’t override by changing ordinary file permissions.
Standard Linux file permissions use . For example, a file owner can grant a group read access. SELinux asks a separate question: If ordinary permissions deny the read, SELinux can’t grant it. If ordinary permissions allow the read, SELinux can still block it.
FAQ
Quick answers to the questions people usually ask about this topic.
Is SELinux enabled on every Linux distribution?
Is SELinux enabled on every Linux distribution?
No. SELinux is typically enabled in enforcing mode by default on Fedora and Red Hat Enterprise Linux (RHEL). Other distributions may use a different security module, such as AppArmor, or leave SELinux disabled. Run getenforce if it’s available to check the current mode rather than assuming the system uses its distribution’s default.
Can moving or copying a file change how SELinux treats it?
Can moving or copying a file change how SELinux treats it?
Yes. A file moved within the same filesystem generally keeps its existing label, which might not be appropriate for its new location. A newly created copy typically gets a label based on the destination and policy, unless the copy preserves the original context. Check the resulting label with ls -lZ. If it doesn’t match the expected file-context mapping, use restorecon to apply that mapping.
When should I use an SELinux boolean instead of relabeling a file?
When should I use an SELinux boolean instead of relabeling a file?
Use a boolean when a service needs an optional capability that the loaded policy already supports. For example, policy may offer a boolean that lets Apache make outbound network connections. Relabel instead when the resource has the wrong type for its intended use. A boolean changes what policy allows; it doesn’t fix an incorrect file label.
Can I troubleshoot one SELinux domain without putting the whole system in permissive mode?
Can I troubleshoot one SELinux domain without putting the whole system in permissive mode?
Yes. On systems that support per-domain permissive mode, an administrator can temporarily make one domain permissive while leaving the rest of SELinux enforcing. This affects every process in that domain, not just one instance of the service, so start by reviewing the AVC logs and restore enforcement promptly if you use it. See Red Hat’s SELinux troubleshooting guide for more diagnostic options.
Where can I practice applying security controls after learning about SELinux?
Where can I practice applying security controls after learning about SELinux?
Explore Pluralsight for guided security labs and feedback that help you put foundational concepts like least privilege and access control into practice. Assessments can help you identify gaps, and practice exams can help you focus your certification prep.
Comments
Add a comment...Pinned by @jaymayor
@jaymayor👉 Master your Security+ skills with Pluralsight here: https://www.jaymayor.com/go/security-plus
Some links may earn a commission. Thanks for your support.
