SELinux is enabled by default on Red Hat-based operating systems, whereas it requires manual configuration on Ubuntu. We will discuss Ubuntu SELinux configuration in a future lesson.

How SELinux Works at a High Level
At its core, SELinux uses security contexts—extended metadata labels on files and processes—to determine which actions are permitted or denied. A typical SELinux file label includes four components in the following order:- SELinux User (e.g.,
unconfined_u) - Role (e.g.,
object_r) - Type (e.g.,
user_home_t) - Level (e.g.,
s0)
unconfined_u, the role object_r, the type or domain user_home_t, and the security level s0.
SELinux’s decision-making process follows these steps:
- User Mapping: The system first checks the SELinux user, which may be different from the Linux login username. Each login is mapped to an SELinux user as specified by the policy.
- Role Verification: The system then determines if the user has the necessary permissions to assume a specific role. For example, a developer may be confined to using roles such as
developer_rordocker_r, while roles likesysadmin_rremain off limits. - Type-Based Access Control: The type component enforces the most granular security. When processes or files are assigned a specific type, they are confined to a strict set of permitted actions.
- Security Level: Although rarely used in standard configurations, the level field enables multi-level security controls for organizations with multiple clearance layers.
Viewing SELinux File Labels
While thels -l command displays standard file permissions, SELinux adds an extra layer of metadata referred to as a security context or label. To view these additional details, use the -Z option:
SELinux Process Contexts
Just as files receive security contexts, processes are also assigned SELinux contexts. To view process contexts, use theps command with the -Z option:
sshd_t domain. Only executables labeled with sshd_exec_t (the type for the SSH daemon file) can run in this domain. To verify the SSH daemon file’s SELinux context, run:
SELinux User Context and Role Mapping
SELinux assigns a security context to each user session. Upon login, a Linux user is mapped to an SELinux user. You can view your current SELinux user context with:unconfined_u along with an associated role and type that impose minimal restrictions by default. Most access control decisions are enforced by the role and type components. For further insight into user-to-role mappings, you can list the allowed logins and SELinux user configurations:
Checking SELinux Enforcement Status
To determine whether SELinux is actively enforcing policies, use the following command:In summary, SELinux uses multi-layered security contexts—composed of user, role, type, and level—to enforce strict access controls on both files and processes. Even if a process is compromised, these stringent policies confine it to a safe security domain, significantly reducing potential system damage.