To configure SELinux on CentOS 7, follow the steps below:
Step 1 : By default, SELinux is enabled. You can check its status using the following command:
Step 2 : You can also check the SELinux configuration using:
Step 3 : SELinux has three modes: Enforcing, Permissive, and Disabled.
- Enforcing: SELinux security policy is enforced.
- Permissive: SELinux does not enforce security policy but logs actions that would be denied in enforcing mode.
- Disabled: SELinux is completely disabled.
Step 4 : Disable SELinux.
If you don't need SELinux for any reason, you can disable it temporarily or permanently:
- Temporarily disable SELinux:
- Permanently disable SELinux: Edit the SELINUX line in /etc/selinux/config file to:
- Reboot the system if SELinux is disabled permanently.
Step 5 : Check the SELinux status again to ensure it's disabled if that was your intention.
Step 6 : Basic SELinux Configuration
- For a basic example, let's install Apache:
Step 7 : Edit the Apache configuration file:
Add the line Listen 8001
to change the default port.
Step 8 : Create a configuration file:
Add configuration to change port and root folder.
Step 9 : Create a folder and index file:
Step 10 : Set appropriate permissions
Step 11 : Open firewall port if necessary:
Step 11 : Install policycoreutils-python:
Step 12 : List SELinux port contexts:
Step 13 : Add a new port for Apache:
Step 14 : Verify the port addition:
Step 15 : Use matchpathcon to compare new directory with default Apache directory:
Step 16 :Match SELinux contexts for the new directory:
Step 17 : Apply the label changes:
Step 18 : Test the Apache configuration:
Step 19 : Restart Apache:
Step 20 : Test the configuration by accessing domain:port
.
Congratulations! Your SELinux configuration on CentOS 7 is complete.