RHCSA Rapid Track
Note
If you plan to take the RHCSA exam, then use the following approach to maximize the benefit of this Comprehensive Review: attempt each lab without viewing the solution buttons or referring to the course content. Use the grading scripts to gauge your progress as you complete each lab.
Configure SSH key-based authentication, change firewall settings, adjust the SELinux mode and an SELinux Boolean, and troubleshoot SELinux issues.
Outcomes
Configure SSH key-based authentication.
Configure firewall settings.
Adjust the SELinux mode and SELinux Booleans.
Troubleshoot SELinux issues.
If you did not reset your workstation and server machines at the end of the last chapter, then save any work that you want to keep from earlier exercises on those machines, and reset them now.
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 rhcsa-compreview3
Specifications
On
serverb, generate an SSH key pair for thestudentuser. Do not protect the private key with a passphrase.Configure the
studentuser onserverato accept login authentication with the SSH key pair that you generated on theserverbmachine. Thestudentuser onserverbmust be able to log in toserveravia SSH without entering a password.On
servera, check the/user-homes/production5directory permissions. Then, configure SELinux to run in thepermissivemode by default.On
serverb, verify that the/localhomedirectory does not exist. Then, configure theproduction5user's home directory to mount the/user-homes/production5network file system. Theservera.lab.example.commachine exports the file system as theservera.lab.example.com:/user-homes/production5NFS share. Use theautofsservice to mount the network share. Verify that theautofsservice creates the/localhome/production5directory with the same permissions as onservera.On
serverb, adjust the appropriate SELinux Boolean so that theproduction5user may use the NFS-mounted home directory after authenticating with an SSH key. If required, useredhatas the password of theproduction5user.On
serverb, adjust the firewall settings to block all connection requests from theserveramachine. Use theserveraIPv4 address (172.25.250.10) to configure the firewall rule.On
serverb, investigate and fix the issue with the failing Apache web service, which listens on port30080/TCPfor connections. Adjust the firewall settings appropriately so that the port30080/TCPis open for incoming connections.
On
serverb, generate an SSH key pair for thestudentuser. Do not protect the private key with a passphrase.Log in to
serverbas thestudentuser.[student@workstation ~]$
ssh student@serverb...output omitted...Use the
ssh-keygencommand to generate an SSH key pair. Do not protect the private key with a passphrase.[student@serverb ~]$
ssh-keygenGenerating public/private rsa key pair. Enter file in which to save the key (/home/student/.ssh/id_rsa):EnterCreated directory '/home/student/.ssh'. Enter passphrase (empty for no passphrase):EnterEnter same passphrase again:EnterYour identification has been saved in /home/student/.ssh/id_rsa. Your public key has been saved in /home/student/.ssh/id_rsa.pub. The key fingerprint is: SHA256:+ijpGqjEQSGBR8ORNchiRTHw/URQksVdHjsHqVBXeYI student@serverb.lab.example.com The key's randomart image is: +---[RSA 3072]----+ |+BBX+o*+o..=+.. | |+.O.oooo .oE+o . | |.+ . . .. .+ .o | |. o . o | | . .S | |... . | |.o. .. | |o .o o | |. .o... . | +----[SHA256]-----+
Configure the
studentuser onserverato accept login authentication with the SSH key pair that you generated on theserverbmachine. Thestudentuser onserverbmust be able to log in toserveravia SSH without entering a password.Send the public key of the newly generated SSH key pair to the
studentuser on theserveramachine.[student@serverb ~]$
ssh-copy-id student@servera/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/student/.ssh/id_rsa.pub" The authenticity of host 'servera (172.25.250.10)' can't be established. ED25519 key fingerprint is SHA256:shYfoFG0Nnv42pv7j+HG+FISmCAm4Bh5jfjwwSMJbrw. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])?yes/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys student@servera's password:studentNumber of key(s) added: 1 Now try logging in to the machine, with: "ssh 'student@servera'" and check to make sure that only the key(s) you wanted were added.Verify that the
studentuser can log in toserverafromserverbwithout entering a password. Do not close the connection.[student@serverb ~]$
ssh student@servera...output omitted... [student@servera ~]$
On
servera, verify the/user-homes/production5directory permissions. Then, configure SELinux to run in thepermissivemode by default.Verify the
/user-homes/production5directory permissions.[student@servera ~]$
ls -ld /user-homes/production5drwx------. 2production5production562 May 6 05:27 /user-homes/production5Edit the
/etc/sysconfig/selinuxfile to set theSELINUXparameter to thepermissivevalue.[student@servera ~]$
sudo vi /etc/sysconfig/selinux...output omitted... #SELINUX=enforcing SELINUX=permissive ...output omitted...Reboot the system.
[student@servera ~]$
sudo systemctl rebootConnection to servera closed by remote host. Connection to servera closed. [student@serverb ~]$
On
serverb, verify that the/localhomedirectory does not exist. Then, configure theproduction5user's home directory to mount the/user-homes/production5network file system. Theservera.lab.example.commachine exports the file system as theservera.lab.example.com:/user-homes/production5NFS share. Use theautofsservice to mount the network share. Verify that theautofsservice creates the/localhome/production5directory with the same permissions as onservera.Verify that the
/localhomedirectory does not exist.[student@serverb ~]$
ls -ld /localhomels: cannot access '/localhome': No such file or directoryOn
serverb, switch to therootuser.[student@serverb ~]$
sudo -i[sudo] password for student:student[root@serverb ~]#Install the
autofspackage.[root@serverb ~]#
dnf install autofs...output omitted... Is this ok [y/N]:y...output omitted... Installed: autofs-1:5.1.7-27.el9.x86_64 libsss_autofs-2.6.2-2.el9.x86_64 Complete!Create the
/etc/auto.master.d/production5.autofsmap file with the following content:/- /etc/auto.production5
Determine the
production5user's home directory.[root@serverb ~]#
getent passwd production5production5:x:5001:5001::/localhome/production5:/bin/bashCreate the
/etc/auto.production5file with the following content:/localhome/production5 -rw servera.lab.example.com:/user-homes/production5
Restart the
autofsservice.[root@serverb ~]#
systemctl restart autofsVerify that the
autofsservice creates the/localhome/production5directory onserverbwith the same permissions as the/user-homes/production5directory onservera.[root@serverb ~]#
ls -ld /localhome/production5drwx------.2production5production562 May 6 05:52 /localhome/production5Note
The
autofsservice shows the correct permissions when you try to access the/localhome/production5shared directory. Before you access this directory, the file permissions incorrectly show that the directory hasrootas the user owner and the group owner. After you try to access the/localhome/production5directory, the correct permissions are shown, whereproduction5is the user owner and the group owner.
On
serverb, adjust the appropriate SELinux Boolean so that theproduction5user may use the NFS-mounted home directory after authenticating with an SSH key. If required, useredhatas the password of theproduction5user.Open a new terminal window and verify from
serverathat theproduction5user cannot log in toserverbwith SSH key-based authentication. An SELinux Boolean is preventing the user from logging in. Fromworkstation, open a new terminal and log in toserveraas thestudentuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$Switch to the
production5user. When prompted, useredhatas the password of theproduction5user.[student@servera ~]$
su - production5Password:redhat[production5@servera ~]$Generate an SSH key pair.
[production5@servera ~]$
ssh-keygenGenerating public/private rsa key pair. Enter file in which to save the key (/home/production5/.ssh/id_rsa):EnterCreated directory '/home/production5/.ssh'. Enter passphrase (empty for no passphrase):EnterEnter same passphrase again:EnterYour identification has been saved in /home/production5/.ssh/id_rsa. Your public key has been saved in /home/production5/.ssh/id_rsa.pub. The key fingerprint is: SHA256:AbUcIBXneyiGIhr4wS1xzs3WqDvbTP+eZuSRn9HQ/cw production5@servera.lab.example.com The key's randomart image is: +---[RSA 3072]----+ | ..=++ | | . = o | | . . = . . | |.. * + o + . . .| |+ = = B S .. o o.| |.+ + + . .+ . . E| |. . . . o o o | | .= . +.o | | ooo .=+ | +----[SHA256]-----+Transfer the public key of the SSH key pair to the
production5user on theserverbmachine. When prompted, useredhatas the password of theproduction5user.[production5@servera ~]$
ssh-copy-id production5@serverb/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/production5/.ssh/id_rsa.pub" The authenticity of host 'serverb (172.25.250.11)' can't be established. ECDSA key fingerprint is SHA256:ciCkaRWF4g6eR9nSdPxQ7KL8czpViXal6BousK544TY. Are you sure you want to continue connecting (yes/no)?yes/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys production5@serverb's password:redhatNumber of key(s) added: 1 Now try logging in to the machine, with: "ssh 'production5@serverb'" and check to make sure that only the key(s) you wanted were added.Use SSH public key-based authentication instead of password-based authentication to log in to
serverbas theproduction5user. This command should fail.[production5@servera ~]$
ssh -o pubkeyauthentication=yes \-o passwordauthentication=no production5@serverbproduction5@serverb: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).On the terminal that is connected to
serverbas therootuser, set theuse_nfs_home_dirsSELinux Boolean totrue.[root@serverb ~]#
setsebool -P use_nfs_home_dirs trueReturn to the terminal that is connected to
serveraas theproduction5user, and use SSH public key-based authentication instead of password-based authentication to log in toserverbas theproduction5user. This command should succeed.[production5@servera ~]$
ssh -o pubkeyauthentication=yes \-o passwordauthentication=no production5@serverb...output omitted... [production5@serverb ~]$Exit and close the terminal that is connected to
serverbas theproduction5user. Keep open the terminal that is connected toserverbas therootuser.
On
serverb, adjust the firewall settings to block all connection requests that originate from theserveramachine. Use theserveraIPv4 address (172.25.250.10) to configure the firewall rule.Add the IPv4 address of
serverato theblockzone.[root@serverb ~]#
firewall-cmd --add-source=172.25.250.10/32 \--zone=block --permanentsuccessReload the changes in the firewall settings.
[root@serverb ~]#
firewall-cmd --reloadsuccess
On
serverb, investigate and fix the issue with the failing Apache web service, which listens on port30080/TCPfor connections. Adjust the firewall settings appropriately so that the port30080/TCPis open for incoming connections.Restart the
httpdservice. This command fails to restart the service.[root@serverb ~]#
systemctl restart httpd.serviceJob for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xeu httpd.service" for details.Investigate why the
httpdservice is failing. A permission error indicates that thehttpddaemon failed to bind to port30080/TCPon startup. SELinux policies can prevent an application from binding to a non-standard port. Press q to quit the command.[root@serverb ~]#
systemctl status httpd.service× httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active:failed(Result: exit-code) since Mon 2022-05-02 13:20:46 EDT; 29s ago Docs: man:httpd.service(8) Process: 2322 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE) Main PID: 2322 (code=exited, status=1/FAILURE) Status: "Reading configuration..." CPU: 30ms May 02 13:20:46 serverb.lab.example.com systemd[1]: Starting The Apache HTTP Server... May 02 13:20:46 serverb.lab.example.com httpd[2322]:(13)Permission denied: AH00072: make_sock: could not bind to address [::]:30080May 02 13:20:46 serverb.lab.example.com httpd[2322]:(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:30080May 02 13:20:46 serverb.lab.example.com httpd[2322]:no listening sockets available, shutting down...output omitted...Determine whether an SELinux policy is preventing the
httpdservice from binding to the30080/TCPport. The log messages reveal that the30080/TCPport does not have the appropriatehttp_port_tSELinux context, and so SELinux prevents thehttpdservice from binding to the port. The log message also produces the syntax of thesemanage portcommand, so that you can fix the issue.[root@serverb ~]#
sealert -a /var/log/audit/audit.log...output omitted... SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 30080. ***** Plugin bind_ports (92.2 confidence) suggests ************************ If you want to allow /usr/sbin/httpd to bind to network port 30080 Then you need to modify the port type. Do # semanage port -a -t PORT_TYPE -p tcp 30080 where PORT_TYPE is one of the following: http_cache_port_t, http_port_t, jboss_management_port_t, jboss_messaging_port_t, ntop_port_t, puppet_port_t. ...output omitted...Set the appropriate SELinux context on the
30080/TCPport for thehttpdservice to bind to it.[root@serverb ~]#
semanage port -a -t http_port_t -p tcp 30080Restart the
httpdservice. This command should successfully restart the service.[root@serverb ~]#
systemctl restart httpdAdd the
30080/TCPport to the defaultpubliczone.[root@serverb ~]#
firewall-cmd --add-port=30080/tcp --permanentsuccess [root@serverb ~]#firewall-cmd --reloadsuccessReturn to the
workstationmachine as thestudentuser.[root@serverb ~]#
exitlogout [student@serverb ~]$exitlogout Connection to serverb closed.