Bookmark this page

Guided Exercise: Accessing the Remote Command Line

In this exercise, you will log into a remote system as different users and execute commands.

Outcomes

You should be able to:

  • Log in to a remote system.

  • Execute commands with the OpenSSH secure shell.

Log in to workstation as student using student as the password.

On workstation, run lab ssh-access start to start the exercise. This script ensures that the environment is setup correctly.

[student@workstation ~]$ lab ssh-access start
  1. From workstation, open an SSH session to servera as student.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ 
  2. Open an SSH session to serverb as student. Accept the host key. Use student as the password when prompted for the password of the student user on serverb.

    [student@servera ~]$ ssh student@serverb
    The authenticity of host 'serverb (172.25.250.11)' can't be established.
    ECDSA key fingerprint is SHA256:ERTdjooOIrIwVSZQnqD5or+JbXfidg0udb3DXBuHWzA.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'serverb,172.25.250.11' (ECDSA) to the list of known hosts.
    student@serverb's password: student
    ...output omitted...
    [student@serverb ~]$ 

    The host key is recorded in the /home/student/.ssh/known_hosts file on servera to identify serverb because the student user has initiated the SSH connection from servera. If the /home/student/.ssh/known_hosts file does not already exist, it comes into existence as a new file along with the new entry in it. The ssh command fails to execute properly if the remote host appears to have a different key than the recorded key.

  3. Run the w command to display the users that are currently logged in to serverb.

    [student@serverb ~]$ w
    18:49:29 up  2:55,  1 user,  load average: 0.00, 0.00, 0.00
    USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
    student  pts/0    172.25.250.10    18:33    0.00s  0.01s  0.00s w

    The preceding output indicates that the student user has logged in to the system from the host with an IP address of 172.25.250.10 which is servera in the classroom network.

    Note

    The IP address of a system identifies the system on a network. You are going to learn about IP addresses in the later chapter.

  4. Exit the student user's shell on serverb.

    [student@serverb ~]$ exit
    logout
    Connection to serverb closed.
    [student@servera ~]$ 
  5. Open an SSH session to serverb as root. Use redhat as the password of the root user.

    [student@servera ~]$ ssh root@serverb
    root@serverb's password: redhat
    ...output omitted...
    [root@serverb ~]# 

    Notice that the preceding ssh command did not ask you to accept the host key because it was found among the known hosts. Should the identity of serverb change at any time, OpenSSH prompts you to verify and accept the new host key.

  6. Run the w command to display the users that are currently logged in to serverb.

    [root@serverb ~]# w
    19:10:28 up  3:16,  1 user,  load average: 0.00, 0.00, 0.00
    USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/0    172.25.250.10    19:09    1.00s  0.01s  0.00s w

    The preceding output indicates that the root user has logged in to the system from the host with an IP address of 172.25.250.10 which is servera in the classroom network.

  7. Exit the root user's shell on serverb.

    [root@serverb ~]# exit
    logout
    Connection to serverb closed.
    [student@servera ~]$ 
  8. Remove the /home/student/.ssh/known_hosts file from servera. This causes ssh to lose the recorded identities of the remote systems.

    [student@servera ~]$ rm /home/student/.ssh/known_hosts

    Host keys can change for legitimate reasons: perhaps the remote machine was replaced because of a hardware failure, or perhaps the remote machine was reinstalled. Usually, it is advisable only to remove the key entry for the particular host in the known_hosts file. Since this particular known_hosts file has only one entry, you can remove the entire file.

  9. Open an SSH session to serverb as student. Accept the host key if asked. Use student as the password when prompted for the password of the student user on serverb.

    [student@servera ~]$ ssh student@serverb
    The authenticity of host 'serverb (172.25.250.11)' can't be established.
    ECDSA key fingerprint is SHA256:ERTdjooOIrIwVSZQnqD5or+JbXfidg0udb3DXBuHWzA.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added 'serverb,172.25.250.11' (ECDSA) to the list of known hosts.
    student@serverb's password: student
    ...output omitted...
    [student@serverb ~]$ 

    Notice that the ssh command asked for your confirmation to accept or reject the host key because it could not find one for the remote host.

  10. Exit the student user's shell on serverb and confirm that a new instance of known_hosts exists on servera.

    [student@serverb ~]$ exit
    logout
    Connection to serverb closed.
    [student@servera ~]$ ls -l /home/student/.ssh/known_hosts
    -rw-r--r--. 1 student student 183 Feb  1 20:26 /home/student/.ssh/known_hosts
  11. Confirm that the new instance of known_hosts file has the host key of serverb.

    [student@servera ~]$ cat /home/student/.ssh/known_hosts
    serverb,172.25.250.11 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI9LEYEhwmU1rNqnbBPukH2Ba0/QBAu9WbS4m03B3MIhhXWKFFNa/UlNjY8NDpEM+hkJe/GmnkcEYMLbCfd9nMA=

    Actual output will vary.

  12. Run hostname remotely on serverb without accessing the interactive shell.

    [student@servera ~]$ ssh student@serverb hostname
    student@serverb's password: student
    serverb.lab.example.com

    The preceding command displayed the full hostname of the remote system serverb.

  13. Exit the student user's shell on servera.

    [student@servera ~]$ exit
    logout
    Connection to servera closed.

Finish

On workstation, run lab ssh-access finish to complete this exercise.

[student@workstation ~]$ lab ssh-access finish

This concludes the guided exercise.

Revision: rh124-8.2-df5a585