Security-Enhanced Linux (SELinux)is an advanced security architecture integrated into the Linux kernel that provides mandatory access control (MAC). 2026 In the digital world where cyber threats have increased, it is the most effective way to protect your servers with the zero trust principle.
In this guide; You will learn in depth the working logic of SELinux, configuration methods, context management and troubleshooting techniques.
root@server:~# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 33
_
Isolate user errors with Mandatory Access Control.
Strict tagging and type checking for every file and process.
Solve problems quickly with audit logs and audit2allow.
Fully sandboxes for Apache, Nginx and MySQL.
Traditional security model in Linux operating systems DAC (Discretionary Access Control) that is, Optional Access Control. In this model, the owner of a file decides who can do what (read, write, execute) on that file. However, root A user or an elevated process can access everything in the system. This creates a major security vulnerability in modern attacks.
SELinux (Security-Enhanced Linux)To close this gap, MAC (Mandatory Access Control) that is, it uses the Mandatory Access Control model. This architecture developed by NSA, contrary to the logic of "Allow everything, block what is prohibited", "Prohibit everything, authorize only what is expressly permitted" It works on the principle.
Especially Shared Hosting and Reseller Hosting environments, SELinux (or derivatives such as CloudLinux CageFS) is vital to prevent one user from accessing another.
SELinux can run in three different modes. It's critical to know what mode you're in when managing your server.
It is the default and recommended mode. Security policies are actively enforced and violations are prevented. Logging is done.
Policies are not enforced, access is not blocked, but violations audit.log is saved to the file. It is used for debugging.
SELinux is completely off. No auditing or logging is done. Not recommended. To turn it back on, the server must be restarted.
To check the current status:
sestatus
# Veya sadece modu görmek for:
getenforce
Changing mode temporarily (resets after reboot):
# Permissive moda geçiş
setenforce 0
# Enforcing moda geçiş
setenforce 1
To change mode permanently /etc/selinux/config You should edit the file:
nano /etc/selinux/config
# SELINUX=enforcing lineını düzenleyin
SELinux marks each process, file, directory and port with a "label". to this tag SELinux Context It is called. A process can only access objects whose tags are compatible.
The tag structure is as follows: user:role:type:level
_u It ends with ._r It ends with ._t It ends with . (Ex: httpd_t, admin_home_t).To see the tags of files -Z We use the parameter:
ls -Z /var/www/html
# Çıktı: system_u:object_r:httpd_sys_content_t:s0 index.html
Especially WordPress or when installing other CMS systems, Apache/Nginx may need permission to write to files (e.g. upload images). Even if the file permissions (chmod 755) are correct, access is denied if the SELinux tag is incorrect.
chcon The command changes the file label, but this change is lost when the file system is relabeled.
# Apache'nin okuyabilmesi for:
chcon -t httpd_sys_content_t /var/www/html/index.php
# Apache'nin yazabilmesi for (Upload klasörleri):
chcon -t httpd_sys_rw_content_t /var/www/html/wp-content/uploads
For changes to be permanent semanage fcontext is used. This adds the rule to the policy database.
# Kuralı veritabanına ekle:
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/uploads(/.*)?"
# Kuralı dosya sistemine uygula:
restorecon -Rv /var/www/html/uploads
| Label Type | Description | Area of Use |
|---|---|---|
httpd_sys_content_t |
Read-only permission | Static files, .php files |
httpd_sys_rw_content_t |
Read and Write permission (Read/Write) | Cache, Upload, Log folders |
httpd_log_t |
log files | Apache/Nginx log directories |
SELinux Booleansare switches that allow you to turn certain features on or off without recompiling the security policy. For example, you must change the boolean settings to allow Apache to connect to the database or send mail.
# Tüm booleanları listele
getsebool -a | grep httpd
# Apache'nin ağ üzerinden veritabanına bağlanmasına izin ver (WordPress for kritik)
setsebool -P httpd_can_network_connect_db 1
# Apache'nin sendmail kullanmasına izin ver
setsebool -P httpd_can_sendmail 1
* -P The parameter ensures that the change is permanent.
When an access is denied, this /var/log/audit/audit.log is saved to the file. To analyze these logs and create automatic permission rules audit2allow The tool is great.
# Son engellenen errorları insan okunabilir formatta gör:
ausearch -m avc -ts recent
# Errorlardan otomatik as bir izin modülü create:
grep httpd /var/log/audit/audit.log | audit2allow -M my_httpd_policy
# Oluşturulan modülü yükle:
semodule -i my_httpd_policy.pp
Frequently asked questions about SELinux and server security.
Enterprise distributions such as AlmaLinux, Rocky Linux, and RHEL adopt the "Secure by Default" philosophy. SELinux is the only built-in mechanism that can protect the system even from services with compromised root privileges.
No, SELinux's impact on performance is negligible on modern processors (%1-2 around). Turning it off does not improve performance, but it destroys a very serious security layer.
Yes, we provide Türkiye Location VDS SELinux is supported in its services in accordance with security standards. If our customers wish, they can manage it themselves or get help from our support team.
Linux permissions (DAC) and SELinux permissions (MAC) are controlled separately. Even if you give the folder 777 , the SELinux tag (e.g. httpd_sys_content_t If) prevents the web server from writing. tag httpd_sys_rw_content_t You should change it to .
With Eka Sunucu's managed server services, SELinux configuration, Firewall settings and Imunify360 protection are made by our experts. You focus on your business, leave security to us.
Security configuration complicated? Our expert team is here for you.
Create a Support Request