selinux - Security-Enhanced Linux, Kernel security module with policies.
Very rarely used statistically, but is more standard in enterprise-geared security.
Example; Oracle Linux, and (RHEL/Red Hat Enterprise Linux), are shipped out of the box with SELinux.
Gentoo is also shipped with SELinux.
Ubuntu does not provide SELinux out of the box. Instead, it uses AppArmor as its default Mandatory Access Control (MAC) system.
Debian does not provide SELinux out of the box; like Ubuntu, it defaults to AppArmor.
Treating everything as a layers in (security/hardening) is essential;
That means SELinux & secureboot are essential.
Both can be tricky to get working properly, but focusing all effort on one layer
and ignoring the bottom layers is a recipe for disaster.
semanage port -l).sshd_t), preventing privilege escalation.getsebool -a | grep ssh).sestatus
Shows whether SELinux is enabled, enforcing, or permissive.
setenforce 0
Switches SELinux to permissive mode (logs but does not enforce policies).
setenforce 1
Switches SELinux back to enforcing mode.
This is set in the file: /etc/selinux/config it will set SELinux to Enforce mode when booting automatically.
SELINUX=enforcing
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
# See also:
#
# NOTE: Up to RHEL 8 release included, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
# grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
# grubby --update-kernel ALL --remove-args selinux
#
SELINUX=enforcing
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
This is set in the file: /etc/selinux/config it will set SELinux to Permissive mode when booting automatically.
SELINUX=Permissive
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#
# NOTE: Up to RHEL 8 release included, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
# grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
# grubby --update-kernel ALL --remove-args selinux
#
SELINUX=Permissive
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
This is set in the file: /etc/selinux/config it will Disable SELinux at boot automatically.
SELINUX=disabled
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
# See also:
#
# NOTE: Up to RHEL 8 release included, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
# grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
# grubby --update-kernel ALL --remove-args selinux
#
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
List and Manage SELinux Ports
semanage port -l | grep ssh
semanage port -a -t ssh_port_t -p tcp 2222
The term "sebool" is not a standard or official name but rather shorthand sometimes used informally to refer to SELinux booleans or the tools (`getsebool`/`setsebool`) that manage them.
SELinux booleans are on/off switches that modify policy behavior at runtime, allowing flexible security adjustments without policy rewriting.
getsebool -a | grep ssh
setsebool -P allow_ssh_keysign off
Turning off allow_ssh_keysign disables host-based authentication that uses the server’s host keys for signing data, reducing potential attack vectors.
It doesn’t impact authorized_keys, which store individual user keys.
SELinux file security assigns unique labels to every file—including individual user files, home directories, and web server content—to enforce granular access permissions under defined policies.
ls -Z /path/to/file
Displays SELinux security context for files.
restorecon -Rv /path/to/directory
Resets files to correct SELinux labels.
chcon -R -t ssh_home_t /custom/path/
If SELinux blocks a SSH from accessing /custom/path, this should solve it.
This example is for sshd, seein in the ssh* part
SELinux Labels for User Home Directories and SSH/sshd
Typically, these labels include:
.ssh directories and related files.Note: These labels can vary slightly depending on the distribution and SELinux policy version.
chcon -R -t ssh_home_t /home/youruser/.ssh
Check Permanent SELinux Booleans
semanage boolean -l | grep ssh
Everything should look like this, unless you have specific needs.
fenced_can_ssh (off, off) Allow fenced to can ssh
selinuxuser_use_ssh_chroot (off, off) Allow selinuxuser to use ssh chroot
ssh_chroot_rw_homedirs (off, off) Allow ssh to chroot rw homedirs
ssh_keysign (off, off) Allow ssh to keysign
ssh_sysadm_login (off, off) Allow ssh to sysadm login
ssh_use_tcpd (off, off) Allow ssh to use tcpd
virt_qemu_ga_manage_ssh (off, off) Allow virt to qemu ga manage ssh
Useful references for learning more about SELinux: