1.6. Enhancing System Security with a Firewall, SELinux and SSH Logings
1.6.1. Ensuring the Firewall is Enabled and Running
1.6.1.1. What is a Firewall and How it Enhances System Security
firewalld service, which is automatically enabled during the installation of Red Hat Enterprise Linux. However, if you explicitly disabled the service, for example in the kickstart configuration, you can re-enable it, as described in Section 1.6.1.2, “Re-enabling the firewalld Service”. For overview of firewall setting options in the Kickstart file, see Red Hat Enterprise Linux 7 Installation Guide.
1.6.1.2. Re-enabling the firewalld Service
firewalld service is disabled after the installation, Red Hat recommends to consider re-enabling it.
firewalld even as a regular user:
~]$ systemctl status firewalldfirewalld is not enabled and running, switch to the root user, and change its status:
~]# systemctl start firewalld~]# systemctl enable firewalldfirewalld, see Red Hat Enterprise Linux 7 Security Guide. For detailed information on configuring and using firewall, see Red Hat Enterprise Linux 7 Security Guide
1.6.2. Ensuring the Appropriate State of SELinux
1.6.2.1. What is SELinux and How it Enhances System Security
SELinux states
- Enabled
- Disabled
SELinux modes
- Enforcing
- Permissive
1.6.2.2. Ensuring the Required State of SELinux
Important
Procedure 1.2. Ensuring the required state of SELinux
- Display the current SELinux mode in effect:
~]$
getenforce - If needed, switch between the SELinux modes.The switch can be either temporary or permanent. A temporary switch is not persistent across reboots, while permanent switch is.
- To temporary switch to either enforcing or permissive mode:
~]#
setenforce Enforcing~]#
setenforce Permissive - To permanently set the SELinux mode, modify the SELINUX variable in the
/etc/selinux/configconfiguration file.For example, to switch SELinux to enforcing mode:# 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
1.6.2.3. Managing SELinux in Cockpit

Figure 1.3. Managing SELinux in Cockpit
1.6.3. Using SSH-based authentication
1.6.3.1. What is SSH-based Authentication and How it Enhances System Security
1.6.3.2. Establishing an SSH Connection
Procedure 1.3. Creating the key files and Copying them to the Server
- Generate a public and a private key:
~]$
ssh-keygenBoth keys are stored in the~/.ssh/directory:~/.ssh/id_rsa.pub- public key~/.ssh/id_rsa- private key
The public key does not need to be secret. It is used to verify the private key. The private key is secret. You can choose to protect the private key with the passphrase that you specify during the key generation process. With the passphrase, authentication is even more secure, but is no longer password-less. You can avoid this using thessh-agentcommand. In this case, you will enter the passphrase only once - at the beginning of a session. For more information onssh-agentconfiguration, see Section 12.2.4, “Using Key-based Authentication”. - Copy the most recently modified public key to a remote machine you want to log into:
~]#
ssh-copy-id USER@hostnameAs a result, you are now able to enter the system in a secure way, but without entering a password.
1.6.3.3. Disabling SSH Root Login
root user, which is enabled by default.
Procedure 1.4. Disabling SSH root login
- Access the
/etc/ssh/sshd_configfile:~]#
vi /etc/ssh/sshd_config - Change the line that reads
#PermitRootLogin yesto:PermitRootLogin no
- Restart the
sshdservice:~]#
systemctl restart sshd

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.