This course is using an outdated version of the technology and is now considered to be Legacy content. It will be removed from our catalog on June 28, 2024. Please be sure to complete your course and finish any remaining labs before that date. We recommend moving to version 9.2, which is the latest version currently available.
In this exercise, you will review simple recommended practices to improve the security of a server system.
Outcomes
You should be able to:
Configure a system to use SSH key-based authentication.
Disable root login to a system.
Verify that the workstation, servera, and serverb systems are started.
Log in to workstation as student using student as the password.
On workstation, run lab securityrisk-recommend setup to verify that the environment is ready.
[student@workstation ~]$lab securityrisk-recommend setup
Configure serverb to allow SSH key-based authentication.
Configuration is successful when the student user on servera can log in to serverb using SSH key-based authentication.
From workstation, log in to servera as the student user.
[student@workstation ~]$ssh student@servera[student@servera ~]$
On servera as the student user, create an SSH key pair with no passphrase.
[student@servera ~]$ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key (/home/student/.ssh/id_rsa):Enter Created directory '/home/student/.ssh'.Enter passphrase (empty for no passphrase):EnterEnter same passphrase again:Enter Your 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:8CttStESwlNmmGot+dXN9cR9x4Hw46gdRmVM5XFj+TQ student@servera.lab.example.com The key's randomart image is: +---[RSA 2048]----+ | o+ .+=oO+| | .o+ =o=EX| | ++ o. o o = o=| | = .o.=. + o o .| | . o .o S + . | | . + .+ . | | o +. . | | . + | | . | +----[SHA256]-----+[student@servera ~]$
On servera, copy the SSH public key to the student account on serverb.
[student@servera ~]$ssh-copy-id student@serverb/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/student/.ssh/id_rsa.pub" The authenticity of host 'serverb (172.25.250.11)' can't be established. ECDSA key fingerprint is SHA256:BMdnasLF5CBGg42Dx77nuXodXdI9dKoEBQGFK5O0HRI. ECDSA key fingerprint is MD5:9e:a8:ec:0c:86:d2:70:34:ef:5a:94:15:6d:48:73:db.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@serverb's password:studentNumber of key(s) added: 1 Now try logging into the machine, with: "ssh 'student@serverb'" and check to make sure that only the key(s) you wanted were added.[student@servera ~]$
On servera, test the ability to use key-based authentication by using the ssh command to connect to serverb and remotely execute the hostname command.
No password is required.
The results are returned to the terminal on servera.
[student@servera ~]$ssh serverb 'hostname'serverb.lab.example.com[student@servera ~]$
On serverb, modify the OpenSSH server configuration file to prohibit logging in by the root user.
Confirm that the current configuration on serverb allows root user to log in using ssh.
On servera, log in to serverb as the root user.
[student@servera ~]$ssh root@serverbroot@serverb's password:redhat[root@serverb ~]#
Logout of serverb.
[root@serverb ~]#logout[student@servera ~]$
On servera, log in to serverb as the student user.
[student@servera ~]$ssh student@serverb[student@serverb ~]$
Use the sudo -i command to change to the root user. If prompted, use student as the password.
[student@serverb ~]$sudo -i[sudo] password for student:student[root@serverb ~]#
As the root user, edit /etc/ssh/sshd_config on serverb so that PermitRootLogin is set to no and uncommented.
When finished, save your changes and exit the text editor.
[root@serverb ~]#vim /etc/ssh/sshd_config...output omitted... PermitRootLoginno...output omitted...
Reload the SSH service on serverb.
When finished, log out from serverb.
[root@serverb ~]#systemctl reload sshd[root@serverb ~]#logout[student@serverb ~]$logoutConnection to serverb closed.[student@servera ~]$
On servera, use SSH to confirm that the root user is not permitted to log in to serverb, but the student user is permitted to log in.
When finished, log out from serverb.
[student@servera ~]$ssh root@serverbPassword:redhatPermission denied, please try again.Password:redhatPermission denied, please try again.Password:redhatPermission denied (publickey,gssapi-keyex,gssapi-with-mic,password)[student@servera ~]$ssh student@serverb...output omitted...[student@serverb ~]$logoutConnection to serverb closed.[student@servera ~]$
Configure SSH on serverb to prevent password authentication.
Confirm that the current configuration on serverb allows users to log in using ssh password authentication.
On servera, log in to serverb as the visitor user.
[student@servera ~]$ssh visitor@serverbvisitor@serverb's password:redhatvisitor@serverb ~]$
Logout of serverb.
[visitor@serverb ~]$logout[student@servera ~]$
From servera, log in to serverb as the student user.
[student@servera ~]$ssh student@serverb...output omitted...[student@serverb ~]$
As the student user on serverb use the sudo -i command to change to the root user.
If prompted, use student as the password.
[student@serverb ~]$sudo -i[sudo] password for student:student[root@serverb ~]#
As the root user, edit the configuration file /etc/ssh/sshd_config so that the PasswordAuthentication entry is set to no.
When finished, save your changes and exit the text editor.
[root@serverb ~]#vim /etc/ssh/sshd_config...output omitted... PasswordAuthenticationno...output omitted...
Reload the SSH service on serverb.
When finished, log out from serverb.
[root@serverb ~]#systemctl reload sshd[root@serverb ~]#logout[student@serverb ~]$logoutConnection to serverb closed.[student@servera ~]$
On servera, verify that the visitor user cannot log in to serverb.
Then, verify that the student user can log in using the SSH keys created earlier.
[student@servera ~]$ssh visitor@serverbPermission denied (publickey,gssapi-keyex,gssapi-with-mic).[student@servera ~]$ssh student@serverb...output omitted...[student@serverb ~]$
Log out from serverb and servera.
[student@serverb ~]$logoutConnection to serverb closed.[student@servera ~]$logoutConnection to servera closed.[student@workstation ~]$