Install SELinux on Debian 10

Select distribution:
Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

Ubuntu has a Mandatory Access Control (MAC) system similar to SELinux, named AppArmor. Both SELinux and AppArmor provide a set of tools to isolate applications from each other to protect the host system from being compromised. AppArmor offers Ubuntu users mandatory access control options, without the perceived difficulty or learning curve that SELinux may have. However, if you are switching to Debian 10, are already familiar with SELinux, and would like to use it to enforce security on your system, you can install it by following the steps in this guide.

Before You Begin

  1. Ensure that you have followed the Getting Started and Securing Your Server guides.

    Note
    This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, you can check our Users and Groups guide.

  2. Update your system:

    sudo apt update
    
    Note
    The Linode kernel does not support SELinux by default. If your system is running a Linode kernel, you will need to change to an upstream kernel in order to use SELinux. See the How to Change Your Linode’s Kernel for more steps. Once you’re kernel is set to the upstream kernel, continue on with the steps in this guide.

Remove AppArmor

  1. Stop AppArmor using systemctl:

    sudo systemctl stop apparmor
    
  2. Purge AppArmor from the system.

    Important

    Do not purge AppArmor if you believe you may reuse it in the future. If you would like to preserve your AppArmor configuration files, use the remove command, instead:

    sudo apt remove apparmor
    
    sudo apt purge apparmor
    
    Note
    If after issuing the `purge command you receive warnings about remaining AppArmor files or directories. You can remove them manually, if desired. This step is not necessary to get a working SELinux installation.
  3. Update your system:

    sudo apt update && sudo apt upgrade -yuf
    
  4. Reboot your Linode

     sudo reboot
    

Install SELinux

  1. Install the SELinux package along with supporting packages to help you manage your installation.

    sudo apt-get install selinux-basics selinux-policy-default auditd
    
  2. Activate your SELinux installation:

     sudo selinux-activate
    

    Your output should resemble the following:

    Activating SE Linux
    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-4.19.0-8-amd64
    Found initrd image: /boot/initrd.img-4.19.0-8-amd64
    done
    SE Linux is activated.  You may need to reboot now.
        
  3. Reboot your Linode for the installation to complete:

     sudo reboot
    
    Note
    After rebooting your system, SELinux should be enabled, but in permissive mode. Permissive mode means any actions that would have been disallowed are allowed, but logged in your system’s audit log located in the /var/log/audit/audit.log file.
  4. Log back into your Linode via SSH. Replace 192.0.2.0 with your own Linode’s IP address.

     ssh username@192.0.2.0
    
  5. Verify the status of your SELinux installation:

     sudo sestatus
    

    You should see a similar output:

    SELinux status:                 enabled
    SELinuxfs mount:                /sys/fs/selinux
    SELinux root directory:         /etc/selinux
    Loaded policy name:             default
    Current mode:                   permissive
    Mode from config file:          permissive
    Policy MLS status:              enabled
    Policy deny_unknown status:     allowed
    Memory protection checking:     requested (insecure)
    Max kernel policy version:      31
        
  6. To put SELinux into enforcing mode, use the setenforce command. When in enforcing mode, any actions not permitted by your system’s are blocked and the corresponding event is logged in the audit log.

     sudo setenforce 1
    
  7. To maintain enforcing mode after reboot, modify the SELinux configuration file in /etc/selinux/config from the default SELINUX=permissive to SELINUX=enforcing:

    File: /etc/selinux/config
    1
    2
    3
    4
    5
    6
    7
    
    # 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.
    SELINUX=enforcing
        
    Note

    If you have set SELinux to enforcing mode, ensure that your SSH port has access before logging out of your session.

    sudo semanage port -l | grep 'ssh'
    

    You should see a similar output if TCP is allowed on port 22.

    ssh_port_t                     tcp      22

    If you do not see the this entry, open the port with the following command:

    sudo semanage port -a -t ssh_port_t -p tcp 22
    

Next Steps

After installing SELinux on your system, use our Getting Started with SELinux Guide to learn the basics of SELinux security.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.