RHCSA Rapid Track
In this review, you will configure SSH key-based authentication, change firewall settings, adjust the SELinux mode and an SELinux Boolean, and troubleshoot SELinux issues.
Outcomes
You should be able to:
Configure SSH keys for key-based authentication.
Configure firewall settings.
Adjust the SELinux mode and SELinux Booleans.
Troubleshoot SELinux issues.
Log in to workstation as student using student as the password.
On workstation, run lab rhcsa-compreview3 start to start the comprehensive review.
This script creates the necessary files to set up the environment correctly.
[student@workstation ~]$lab rhcsa-compreview3 start
Instructions
Perform the following tasks to complete the comprehensive review:
Generate SSH keys for the
studentuser onserverb. Do not protect the private key with a passphrase.On
servera, configure thestudentuser to accept login authentication using the SSH key pair created forstudentonserverb. Thestudentuser onserverbshould be able to log in toserverausing SSH without entering a password. Usestudentas the password of thestudentuser, if required.On
servera, change the default SELinux mode topermissive.Configure
serverbto automatically mount the home directory of theproduction5user when the user logs in, using the network file system/home-directories/production5. This network file system is exported fromservera.lab.example.com. Adjust the appropriate SELinux Boolean so thatproduction5can use the NFS-mounted home directory onserverbafter authenticating via SSH key-based authentication. Theproduction5user's password isredhat.On
serverb, adjust the firewall settings so that the SSH connections originating fromserveraare rejected.On
serverb, investigate and fix the issue with the Apache HTTPD daemon, which is configured to listen on port30080/TCP, but which fails to start. Adjust the firewall settings appropriately so that the port30080/TCPis open for incoming connections.
From
workstation, open an SSH session toserverbasstudent.Generate SSH keys for the
studentuser onserverbusing thessh-keygencommand. 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:1TPZ4TXYwiGWfExUGtRTHgfKQbF9hVuLa+VmH4vgkFY student@serverb.lab.example.com The key's randomart image is: +---[RSA 2048]----+ | .+@BO**| | .=.#+B*| | . X.*o=| | . E +.+ | | S o + | | + . o = | | . o o + +| | . . ..| | | +----[SHA256]-----+
On
servera, configure thestudentuser to accept login authentication using the SSH key pair you created forstudentonserverb. Thestudentuser onserverbshould be able to log in toserverausing SSH without entering a password. Usestudentas the password of thestudentuser, when required.Use the
ssh-copy-idcommand to transfer the public key of the SSH key pair ofstudentonserverbtostudentonservera. Usestudentas the password of thestudentuser, if prompted.[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. ECDSA key fingerprint is SHA256:g/fIMtVzDWTbTi1l0OwC30sL6cHmro9Tf563NxmeyyE.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 keysstudent@servera's password:studentNumber of key(s) added: 1 Now try logging into the machine, with: "ssh 'student@servera'" and check to make sure that only the key(s) you wanted were added.Use the
sshcommand to verify that thestudentuser can log in toserverafromserverbwithout entering a password.[student@serverb ~]$ssh student@servera...output omitted...[student@servera ~]$
On
servera, change the default SELinux mode topermissive.Edit
/etc/sysconfig/selinuxto set the value of the parameterSELINUXtopermissive. You can use thesudo vi /etc/sysconfig/selinuxcommand to edit the configuration file as the superuser. Use the passwordstudent, if prompted....output omitted... #SELINUX=enforcing SELINUX=permissive ...output omitted...
Use the
sudo systemctl rebootcommand to reboot the system as the superuser.[student@servera ~]$sudo systemctl rebootConnection to servera closed by remote host. Connection to servera closed.[student@serverb ~]$
Configure
serverbto automatically mount the home directory of theproduction5user when the user logs in, using the network file system/home-directories/production5. This network file system is exported fromservera.lab.example.com. Adjust the appropriate SELinux Boolean so thatproduction5can use the NFS-mounted home directory onserverbafter authenticating via SSH key-based authentication. Theproduction5user's password isredhat.On
serverb, use thesudo -icommand to switch to therootuser account.[student@serverb ~]$sudo -i[sudo] password for student:student[root@serverb ~]#Install the autofs package.
[root@serverb ~]#yum install autofs...output omitted...Is this ok [y/N]:y...output omitted... Installed: autofs-1:5.1.4-29.el8.x86_64 Complete!Create the
autofsmaster map file called/etc/auto.master.d/production5.autofswith the following content./- /etc/auto.production5
Retrieve the details of the
production5user to get the home directory path.[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:/home-directories/production5
Restart the
autofsservice.[root@serverb ~]#systemctl restart autofs
On
servera, verify that theproduction5user is not able to log in toserverbusing SSH public-key authentication. An SELinux Boolean causes this issue which you will fix in the following steps.From
workstation, open an SSH session toserveraasstudent.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$Switch to the
production5user using the passwordredhat.[student@servera ~]$su - production5Password:redhat[production5@servera ~]$Use the
ssh-keygencommand to generate the SSH keys asproduction5.[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:zmin1nmCt4H8LA+4FPimtdg81nl7ATbInUFW3HSPxk4 production5@servera.lab.example.com The key's randomart image is: +---[RSA 2048]----+ | .oo.o. . | | .. . .o o | | . o o E .| | . o * + | | . . .So . | | . + = . | | *.*+=. . | | Oo+***.o | | o.=o.=** | +----[SHA256]-----+Use the
ssh-copy-idcommand to transfer the public key of the SSH key pair ofproduction5onserveratoproduction5onserverb. Useredhatas the password of theproduction5user, if prompted.[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 keysproduction5@serverb's password:redhatNumber of key(s) added: 1 Now try logging into the machine, with: "ssh 'production5@serverb'" and check to make sure that only the key(s) you wanted were added.Use the SSH public key-based authentication instead of password-based authentication to log in to
serverbasproduction5. 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).
Set the appropriate SELinux Boolean setting on
serverb, so thatproduction5can log in toserverbusing the SSH public key-based authentication and use the home directory.On
serverbasroot, set theuse_nfs_home_dirsSELinux Boolean totrue.[root@serverb ~]#setsebool -P use_nfs_home_dirs trueUse the SSH public key-based authentication instead of password-based authentication to log in to
serverbasproduction5. This command should succeed.[production5@servera ~]$ssh -o pubkeyauthentication=yes \-o passwordauthentication=no production5@serverb...output omitted...[production5@serverb ~]$
On
serverb, adjust the firewall settings so that SSH connections originating fromserveraare rejected. Theserverasystem uses the IPv4 address172.25.250.10.Use the
firewall-cmdcommand to add the IPv4 address ofserverato thefirewalldzone calledblock.[root@serverb ~]#firewall-cmd --add-source=172.25.250.10/32 \--zone=block --permanentsuccessUse the
firewall-cmd --reloadcommand to reload the changes in the firewall settings.[root@serverb ~]#firewall-cmd --reloadsuccess
On
serverb, investigate and fix the issue with the Apache HTTPD daemon, which is configured to listen on port30080/TCP, but which fails to start. Adjust the firewall settings appropriately so that port30080/TCPis open for incoming connections.Use the
systemctlcommand to restart thehttpdservice. 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 -xe" for details.Use the
systemctl statuscommand to investigate the reason for the failure of thehttpdservice.[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 2019-04-15 06:42:41 EDT; 5min ago Docs: man:httpd.service(8) Process: 27313 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE) Main PID: 27313 (code=exited, status=1/FAILURE) Status: "Reading configuration..." Apr 15 06:42:41 serverb.lab.example.com systemd[1]: Starting The Apache HTTP Server...Apr 15 06:42:41 serverb.lab.example.com httpd[27313]: (13)Permission denied: AH00072: make_sock: could not bind to address [::]:30080Apr 15 06:42:41 serverb.lab.example.com httpd[27313]: (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:30080Apr 15 06:42:41 serverb.lab.example.com httpd[27313]: no listening sockets available, shutting down Apr 15 06:42:41 serverb.lab.example.com httpd[27313]: AH00015: Unable to open logs Apr 15 06:42:41 serverb.lab.example.com systemd[1]: httpd.service: Main process exited, code=exited, status=1/FAILURE Apr 15 06:42:41 serverb.lab.example.com systemd[1]: httpd.service: Failed with result 'exit-code'. Apr 15 06:42:41 serverb.lab.example.com systemd[1]: Failed to start The Apache HTTP Server.Notice the permission error in the preceding output, which signifies that the
httpddaemon failed to bind to port30080/TCP. The SELinux policy can be a potential restriction for an application to bind to a port. Press q to quit the precedingsystemctlcommand.Use the
sealertcommand to determine if an SELinux policy is preventinghttpdfrom binding to port30080/TCP.[root@serverb ~]#sealert -a /var/log/audit/audit.log100% done found 1 alerts in /var/log/audit/audit.log -------------------------------------------------------------------------------- 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...The preceding log message reveals that the port
30080/TCPdoes not have the appropriate SELinux contexthttp_port_t, causing SELinux to preventhttpdto bind to this port. The log message also produces the syntax of thesemanage portcommand so that you can easily fix the issue.Use the
semanage portcommand to set the appropriate SELinux context on the port30080/TCPforhttpdto bind to it.[root@serverb ~]#semanage port -a -t http_port_t -p tcp 30080Use the
systemctlcommand to restarthttpd. This command should successfully restart the service.[root@serverb ~]#systemctl restart httpdAdd the port
30080/TCPto the defaultfirewalldzone calledpublic.[root@serverb ~]#firewall-cmd --add-port=30080/tcp --permanentsuccess[root@serverb ~]#firewall-cmd --reloadsuccessExit the
rootuser's shell.[root@serverb ~]#exitlogoutLog off from
serverb.[student@serverb ~]$exitlogout Connection to serverb closed.