Bookmark this page

Lab: Configuring and Securing OpenSSH Service

Performance Checklist

In this lab, you will add security measures to the ssh service.

Outcomes

Students will set up SSH keys, configure and exclusively allow user key-based authentication, and lock down the OpenSSH service to prevent the root user from logging into the system by using SSH.

Reset the desktopX and serverX systems.

Run lab ssh setup as the student user on both desktopX and serverX. This will create a user account called visitor with a password of password.

[student@desktopX ~]$ lab ssh setup
[student@serverX ~]$ lab ssh setup

Unless specified, all steps are to be performed as user visitor.

  1. Generate SSH keys on desktopX for user visitor and copy the public key to the visitor account on serverX.

    1. Generate a SSH public key on desktopX as user visitor.

      [visitor@desktopX ~]$ ssh-keygen
      
    2. Install the SSH public key generated previously on desktopX to the visitor account on serverX.

      [visitor@desktopX ~]$ ssh-copy-id serverX
      The authenticity of host 'serverX (172.25.X.11)' can't be established.
      ECDSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
      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
      visitor@serverX's password: password
      
      Number of key(s) added: 1
      
      Now try logging into the machine, with:   "ssh 'visitor@serverX'"
      and check to make sure that only the key(s) you wanted were added.
      
      
  2. Disable ssh login for the root user and password-based SSH authentication on serverX.

    1. Log into the serverX virtual machine as user root.

      [visitor@desktopX ~]$ ssh root@serverX
    2. Customize the ssh service on serverX by disabling SSH connections for the user root and only allow key-based login.

      Set the necessary config file parameters in /etc/ssh/sshd_config:

      PermitRootLogin no
      PasswordAuthentication no

    3. Restart the sshd service on serverX.

      [root@serverX ~]# systemctl restart sshd
  3. Verify that user root is not allowed to login to serverX by using ssh, while user visitor is with the private key.

    1. On a different terminal window on desktopX, validate that user root cannot connect to serverX with the ssh command. It should fail because we disabled root logins with the ssh service.

      [visitor@desktopX ~]$ ssh root@serverX
      Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
      
    2. Try logging in as user student to serverX from desktopX by using ssh. It should fail because we did not add the public key from that user to the student account on the serverX machine.

      [visitor@desktopX ~]$ ssh student@serverX
      Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
      
    3. Verify the ssh service is still accepting key-based authentication by successfully connecting to serverX as user visitor with the ssh command.

      [visitor@desktopX ~]$ ssh visitor@serverX
      [visitor@serverX ~]$ 
      
Revision: rh124-7-1b00421