What is SELinux (Security-Enhanced Linux) 

Try this guide with our instant dedicated server for as low as 40 Euros

selinux in linux

Imagine a luxurious resort where each guest has an access card that allows entry only to their allotted rooms. This security measure prevents unnecessary breaches and maintains the integrity of the guest experience.

This is what Security-Enhanced Linux or SELinux does for your Linux system.

Designed to provide robust security mechanisms, SELinux goes beyond traditional access controls present in all distributions. It provides a meticulous and comprehensive capability for data integrity and confidentiality.

By enforcing strict access permissions, SELinux guarantees that every application and user can access only what they are allowed. This creates a very secure digital environment for your business processes and operations.

For system administrators, SELinux is an invaluable tool that blocks unauthorized access to system resources and enforces privilege separation between users and processes. This leads to more efficient access management at all levels.

In this tutorial, we will discuss SELinux in Linux and how to configure it on your system. We will start with an introduction to SELinux and then go into the details of the configuration.

Table Of Contents

  1. What is SELinux?
  2. How Does SELinux Work?
    1. SELinux Policies
    2. Mandatory Access Controls (MAC)
    3. SELinux Labels and Type Enforcement
    4. SELinux Modes
  3. SELinux Vs Linux
    1. Enhanced Security Features
    2. Policy Enforcement
    3. Access Control
  4. SELinux Vs AppArmor
    1. Access Control
    2. Predominant Use in Ubuntu Distributions
    3. Configuration and Usability
  5. How to Configure SELinux?
    1. Temporary Configuration of SELinux
    2. Permanent Configuration of SELinux
  6. Conclusion
  7. FAQs

What is SELinux?

Security-Enhanced Linux (SELinux), developed by the NSA and Red Hat, is a kernel security module for Linux. It is available for most Linux distributions but is mainly used on RHEL, Fedora, and most of the distributions based on these distros.

SELinux enforces Mandatory Access Control (MAC) policies, allowing sysadmins to set centralized security access policies and specify which users and processes can access certain resources.

It operates on a least-privilege model, blocking access by default. Administrators have to grant access permission for resource access.

With SELinux, sysadmins can differentiate between a user and the applications they run. For instance, while the user shell has full access to the home directory, a mail client run by the user is blocked from accessing certain subdirectories within the directory.

SELinux enhances protection by separating security policies and their enforcement within the kernel, giving sysadmins more control over system security.

Since SELinux is integrated into the Linux kernel, it is always active, and users and processes cannot disable it.

How Does SELinux Work?

SELinux operates through mandatory access controls (MAC), where sysadmins specify which users and processes can access particular resources, rather than relying on broad permissions.

Let us now discuss the components that determine how SELinux works.

SELinux Policies

SELinux by default blocks all applications and users, permitting access only to those explicitly specified in the security policies.

Security policies in SELinux are rules that dictate which system resources are accessible to specific users or processes. These rules define granular permissions for users, processes, and resources.

SELinux caches every access decision in the Access Vector Cache (AVC), speeding up the access control process.

When a process requests access to a resource, SELinux first checks the AVC for a prior decision. If so, it promptly denies or grants the request, conserving time and resources. If not, SELinux refers to the policy rules to make the decision.

Mandatory Access Controls (MAC)

Unlike Discretionary Access Control (DAC), where users have the discretion to set permissions on their own files, MAC policies are centrally managed by the system administrator.

It is a crucial feature of SELinux, where it can assign distinct permissions to various processes. For instance, an administrator can establish a policy permitting a web server process to read and write to the document root while restricting other processes.

SELinux also facilitates context-based access controls. For instance, a sysadmin can establish a policy permitting a web server to read and write to the root only under specific conditions, such as when the request originates from a trusted IP address.

SELinux Labels and Type Enforcement

Labels and Type enforcement are core concepts in SELinux.

SELinux utilizes labels in access control security policies to decide which actions are permitted for each resource. Admins assign labels to processes, networks, ports, and files.

The basic syntax of the label is as follows:


Labels consist of four main components: User, Role, Type, and Level.


Represents the SELinux user, which is often mapped to a regular Linux user account.


Defines the role of the user or process within the SELinux environment (e.g., webserver_u, system_admin_r).


Determines the type enforcement. Each type defines a distinct set of permissions, controlling what actions a labeled object can perform or be subjected to.

SELinux compares the resource type to the process or user type when access is requested. Subsequently, the module grants or denies access depending on the permissions linked to those types.

Level (optional)

Represents the security clearance level, often used in environments requiring Multi-Level Security (MLS). It is typically expressed as a range and it adds a layer of granularity in controlling access based on sensitivity and clearance levels.

SELinux Modes

SELinux modes are one of the key features that enable sysadmins to effectively manage and troubleshoot SELinux-enabled systems.

SELinux operates in three distinct modes, each providing a different level of security enforcement and flexibility. They are:

Enforcing mode

Enforcing mode is the default and most secure SELinux mode, where SELinux strictly enforces access control policies set by the sysadmin. Users cannot override these policies and unauthorized access attempts are denied and logged in AVC.

Permissive mode

Less secure than enforcing mode but still offers protection. In this mode, SELinux does not enforce policies but logs events when unauthorized access attempts occur. This helps sysadmins monitor potential security issues and adjust policies as required before switching to enforcing mode.

Disabled mode

The disabled mode is the least secure mode, offering no protection for system resources. SELinux does not enforce access control policies in this mode. It is typically used for testing or debugging purposes.

Now that you have a basic understanding of SELinux and its components, let us compare SELinux with Linux and with AppArmor to better understand SELinux.

SELinux Vs Linux

SELinux and Linux are separate entities. Linux is an operating system, while SELinux is a security module integrated into its kernel. The key differences between SELinux and Linux are:

Enhanced Security Features

Linux manages hardware and software resources, providing a foundation for software development. Conversely, SELinux acts as a security component safeguarding Linux against malicious software and unauthorized access.

Policy Enforcement

Unlike Linux, where users can set permissions at their discretion, SELinux enforces centrally managed security policies. This illustrates the additional layers of security SELinux provides.

Access Control

Users and apps with the necessary privileges have unrestricted system access in Linux setups. This mechanism is known as Discretionary Access Control (DAC).

Conversely, SELinux operates differently. SELinux allows administrators to define permissions for each user, process, and resource. It blocks unauthorized access attempts, enabling sysadmins to regulate access to specific system processes or files through security policies.

Let us now compare SELinux with AppArmor.

SELinux Vs AppArmor

AppArmor serves as the primary competitor to SELinux in Debian-based distributions. Although both are MAC security frameworks designed to safeguard systems from malicious software and unauthorized access to system resources, AppArmor and SELinux vary in several aspects:

Access Control

Unlike SELinux, AppArmor doesn’t employ type enforcement; instead, it regulates access through configuration files.

AppArmor utilizes profiles, which are sets of rules governing permissions for individual programs specified within a configuration file. It blocks the action and logs the event when a program attempts an unauthorized action according to its profile.

In contrast, SELinux employs MAC, allowing sysadmins to define permissions for each user, process, and resource on the system.

Predominant Use in Ubuntu Distributions

AppArmor is predominantly utilized on SUSE and Ubuntu, although both systems are accessible in all major Linux distributions.

SELinux, initially developed for Fedora and Red Hat Enterprise Linux (RHEL) is generally used in these Linux distributions. Its widespread adoption in enterprise environments highlights its robustness and flexibility.

Configuration and Usability

AppArmor is simpler to learn, configure, and manage. However. it has slower startup times, less flexibility, and lower control levels.

Conversely, SELinux is more complex to configure and manage, offering sysadmins fine-grained control based on users, processes, and contexts.

Let us now discuss how to configure them to suit the user requirements.

How to Configure SELinux?

Linux comes with preinstalled SELinux security policies, simplifying configuration. However, administrators can also define custom security policies based on specific requirements.

SELinux can be configured either permanently, ensuring settings persist across reboots, or temporarily for the current session.

Temporary Configuration of SELinux

The temporary configuration of SELinux applies only to the current session. These settings revert to the default values once the system reboots. Temporary configuration of SELinux is used for testing purposes or troubleshooting specific access issues.

To activate enforcing mode, run the setenforce command with the variable set to 1.

# setenforce 1

The command doesn’t have any status output. Therefore, to verify the change, use either of the commands: sestatus or getenforce.

The sestatus offers more detailed information, while getenforce simply outputs the current mode.

To verify the changes made in SELinux, execute the following command in the terminal:

# sestatus

To verify the changes made in SELinux, execute the following command

The output confirms that the current mode is enforced, even though the configuration file variable remains permissive. Restarting the terminal will revert the current mode back to permissive.

Alternatively, you can verify using getenforce command. The syntax of the command is:

# getenforce

Alternatively, you can verify using getenforce command

Next, let us understand how to configure SELinux permanently.

Permanent Configuration of SELinux

Permanent changes in SELinux persist across the system even though the session restarts.

Follow these steps to configure SELinux permanently.

Note: /etc/selinux/config file contains various SELinux configuration options, including the operational mode. Therefore, to configure SELinux, we recommend modifying the /etc/selinux/config file.

Open the SELinux config file in your preferred text editor. We recommend using Vim or Nano ( We will be using Vim in this tutorial).

# vim /etc/selinux/config

Open the SELinux config file in your preferred text editor

Next, locate the line SELINUX=, and modify its value to permissive as follows:


Next, locate the line SELINUX=, and modify its value to permissive

Save your changes and exit the file.

Reboot the system to take the changes into effect.

Verify the change using the sestatus command.

# sestatus

Verify the change using the sestatus command

Here, the sestatus command displays if the current SELinux mode is permissive, confirming the change made in the config file.


By now you have a basic understanding of what Security Enhanced Linux (SELinux) entails and how to configure a basic security setup.

Armed with this knowledge, the next step is to investigate enabling SELinux on CentOS. With SELinux offering additional protection through its sophisticated security architecture, mastering its configuration opens doors to enhanced system security and control.

Understanding SELinux’s nuances empowers administrators to tailor security measures effectively, fortifying their systems against potential threats and vulnerabilities.


Q. What is a security context, and how does it relate to SELinux rules?

A security context is a crucial component of SELinux, defining the security attributes of a process or resource. It includes information such as the security level, file modes, and the security server responsible for enforcing security decisions. SELinux rules leverage these security contexts to enforce mandatory access control policies, ensuring that only authorized users and processes can access specific resources based on their security attributes.

Q. How does SELinux contribute to Multi-level Security and enhance system security?

SELinux operates as a powerful security layer within the Linux kernel, implementing mandatory access control policies to enforce strict security measures. By enforcing security contexts and rules, SELinux enhances the system’s security level, preventing unauthorized access and mitigating potential security threats. This robust security enhancement facilitates Multi-level Security, enabling administrators to define and enforce security policies at multiple levels of granularity, thereby safeguarding sensitive data and resources effectively.

Q. What role does SELinux play in enforcing security policies and enhancing system security?

SELinux serves as a server within the Linux kernel, responsible for enforcing security decisions based on defined security contexts and rules. Through mandatory access control policies, SELinux restricts access to system resources, ensuring that only authorized users and processes can perform specific actions. By enforcing stringent security measures, SELinux strengthens the system’s security layer, protecting against unauthorized access attempts and enhancing overall system security.

Q. What privileges does the root user possess in SELinux access controls, and how does it relate to unlimited access?

The root user holds elevated privileges within SELinux access controls, often referred to as superuser or administrator. However, unlike traditional Linux systems where the root user enjoys unlimited access to system resources, SELinux imposes restrictions based on defined security policies. These policies, defined using a policy language, specify integrity requirements and access control mechanisms, ensuring that even the root user’s actions are subject to mandatory access control.

Q. How does SELinux contribute to enhancing security on Debian-based platforms?

SELinux provides robust security enhancements for Debian-based platforms, including Debian and Ubuntu, by implementing Role-based Access Control (RBAC) and other advanced security mechanisms. By enforcing strict access controls and integrity requirements, SELinux mitigates security risks such as buffer overflows and unauthorized kernel modifications, thereby fortifying the security layer of Debian-based systems.

Q. What role does SELinux play in regulating access to files and preventing unauthorized access?

SELinux employs sophisticated access control mechanisms to regulate access to files and other system resources. Through SELinux access controls, administrators can define granular permissions and restrictions, specifying which users and processes are allowed to access specific files based on their security contexts. By enforcing these access controls, SELinux prevents unauthorized access attempts and strengthens the overall security posture of the system.

Q. How does SELinux address security vulnerabilities such as buffer overflows and unauthorized kernel modifications?

SELinux addresses security vulnerabilities such as buffer overflows and unauthorized kernel modifications by implementing stringent security measures and integrity requirements. SELinux mitigates the risk of buffer overflows by restricting access and enforcing policies at the kernel level, which can lead to system compromises. Additionally, SELinux prevents unauthorized kernel modifications, safeguarding system integrity and enhancing overall security resilience.

Q. How does SELinux contribute to policy development and implementing additional security controls?

SELinux facilitates policy development by allowing administrators to define fine-grained access controls and security policies using a policy language. By specifying SELinux contexts and file contexts, administrators can tailor security measures to meet the specific requirements of their systems. This additional layer of security control enhances system resilience and mitigates risks associated with careless users or attempts to bypass application security mechanisms.

Q. What role do SELinux contexts play in enhancing application security mechanisms?

SELinux contexts are vital in enhancing application security mechanisms by providing additional security controls and enforcing strict access policies. By assigning SELinux contexts to processes and resources, administrators can define the scope of access and restrict applications’ actions. This helps prevent the bypassing of application security measures and ensures that only authorized actions are allowed, bolstering overall system security.

Q. How does SELinux address the risks posed by careless users and attempts to bypass application security?

SELinux mitigates the risks associated with careless users and attempts to bypass application security by implementing additional security controls and access restrictions. By enforcing SELinux contexts and policies, SELinux prevents unauthorized access to sensitive resources and restricts user and application actions. This helps minimize the impact of security breaches and strengthens the overall security posture of the system.

Q. What is the role of configuration mode in defining access policy rules within SELinux?

Configuration mode in SELinux allows administrators to specify access policy rules that govern the behavior of application processes and their interactions with system resources. By configuring SELinux in different modes, administrators can enforce additional rules and requirements to meet specific security needs, ensuring that only authorized actions are allowed and unauthorized access is blocked.

Q. How does SELinux enhance application security by implementing additional rules and permission levels?

SELinux serves as an all-in-one security solution by implementing additional rules and permission levels to enhance application security. By enforcing strict access controls and configuration requirements, SELinux strengthens the security posture of application processes, preventing unauthorized access and mitigating the risks associated with security breaches.

Q. What are the additional requirements SELinux enforces to provide an overview of its architectural components?

SELinux imposes additional requirements on system processes and resources to provide an overview of its architectural components. These requirements include enforcing access policy rules, configuring SELinux in different modes, and defining application permission levels. By adhering to these requirements, SELinux ensures that all architectural components work together seamlessly to provide comprehensive security protection.

Q. How does SELinux serve as an all-in-one security solution, integrating architectural components to enhance system security?

SELinux is an all-in-one security solution that integrates architectural components that enforce access policy rules, configure system modes, and define application permission levels. This comprehensive approach ensures that SELinux addresses all aspects of system security, from access control to application process management. By providing a unified framework for security enforcement, SELinux enhances overall system resilience and mitigates security risks effectively.

Try this guide with our instant dedicated server for as low as 40 Euros