In this lab, you manage SELinux modes, both temporarily and persistently.
Outcomes
View and set the current SELinux mode.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start selinux-opsmode
Instructions
On the workstation machine, use the ssh command to log in to the servera machine as the student user and then switch to the root user.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#
Change the default SELinux mode to permissive.
Use the getenforce command to verify the current SELinux mode on the servera machine.
[root@servera ~]# getenforce
EnforcingUse the vim /etc/selinux/config command to edit the configuration file.
Change the SELINUX parameter from enforcing to permissive mode.
[root@servera ~]# vim /etc/selinux/configUse the grep command to confirm that the SELINUX parameter displays the permissive mode.
[root@servera ~]#grep '^SELINUX' /etc/selinux/configSELINUX=permissiveSELINUXTYPE=targeted
Use the setenforce command to change the SELINUX parameter to the permissive mode and verify the change.
[root@servera ~]#setenforce 0[root@servera ~]#getenforcePermissive
Change the default SELinux mode back to the enforcing mode in the configuration file.
Use the vim /etc/selinux/config command to edit the configuration file.
Change the SELINUX parameter from permissive to enforcing mode.
[root@servera ~]# vim /etc/selinux/configUse the grep command to confirm that the SELINUX parameter sets the enforcing mode on booting.
[root@servera ~]#grep '^SELINUX' /etc/selinux/configSELINUX=enforcingSELINUXTYPE=targeted
Set the SELinux mode to enforcing on the command line.
Reboot the servera machine and verify the SELinux mode.
Use the setenforce command to set the current SELinux mode to the enforcing mode.
Use the getenforce command to confirm that SELinux is set to the enforcing mode.
[root@servera ~]#setenforce 1[root@servera ~]#getenforceEnforcing
Reboot the servera machine to implement the persistent configuration.
[root@servera ~]# systemctl reboot
Connection to servera closed by remote host.
Connection to servera closed.
[student@workstation ~]$Log in to the servera machine and verify the SELinux mode.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#getenforceEnforcing
Return to the workstation machine as the student user.
[root@servera ~]#exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$
This concludes the section.