To configure SELinux on Rocky Linux 9, follow the steps below.
Step 1 : By default, SELinux is enabled. Verify the SELinux status using the command:
Step 2 : To get more detailed status information, use:
Step 3 : SELinux operates in three modes: Enforcing, Permissive, and Disabled.
- Enforcing: Enforces security policies.
- Permissive: Logs violations but doesn't enforce them.
- Disabled: SELinux is turned off.
Step 4 : Disable SELinux
If SELinux is not needed, you can disable it temporarily, permanently.
- Disable Temporarily
- Disable Permanently
Edit the /etc/selinux/config
file
And set SELINUX=disabled
. Save the file.
- Reboot : If SELinux is disabled permanently, reboot the system.
Step 5 : Check the SELinux status to ensure it's disabled or in the desired mode.
Basic SELinux Configuration
Step 6 : Install Apache.
Step 7 : Edit /etc/httpd/conf/httpd.conf
and add Listen 8001
.
Add the following line:
Save and exit the editor.
Step 8 : Create a configuration for port change and root folder.
Add the following content:
Save and exit the editor.
Step 9 : Create the root folder and set permissions.
Step 10 : Test the configuration.
If the configuration is correct, you should see:
Step 11 : Open firewall port if necessary.
Step 12 : Install policycoreutils-python-utils
Step 13 : Check SELinux ports.
Step 14 : Find specific port type.
Step 15 : Add a new port:
Step 16 : Verify the port.
You should see an entry for port 8001 with the correct SELinux type.
Step 17 : Restart Apache.
Step 18 : Match SELinux Contexts
Step 19 : Apply SELinux Context Changes
Step 20 : Open a web browser and navigate to http://your_domain_or_IP:8001
to check if the Apache server is serving content from the specified directory.
Congratulations! You have successfully configured SELinux on Rocky Linux 9.