Bookmark this page

Guided Exercise: Using SSH Key-based Authentication

In this lab, you will set up SSH key-based authentication.

Outcomes

Students will set up SSH user key-based authentication to initiate SSH connections.

  1. Create an SSH key pair as student on desktopX using no passphrase.

    [student@desktopX ~]$ ssh-keygen
    Generating 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): Enter
    Enter 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.
    ...
  2. Send the SSH public key to the student account on serverX.

    [student@desktopX ~]$ ssh-copy-id serverX
    The authenticity of host 'serverX (172.25.X.11)' can't be established.
    ECDSA key fingerprint is 33:fa:a1:3c:98:30:ff:f6:d4:99:00:4e:7f:84:3e:c3.
    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
    student@serverX's password: student
    
    Number of key(s) added: 1
    
    Now try logging into the machine, with:   "ssh 'student@serverX'"
    and check to make sure that only the key(s) you wanted were added.
    
  3. Run the hostname command by using ssh to display the hostname of the serverX.example.com machine without the need to enter a password.

    [student@desktopX ~]$ ssh serverX 'hostname'
    serverX.example.com
Revision: rh124-7-1b00421