Generating and Exchanging SSH Keys Between Servers

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

You have been tasked with finding a way to make some scripts work between servers, without having to store passwords in the script files. You have discovered that one way to do this is by creating a trust relationship between servers by sharing SSH keys between the servers. In this hands-on lab, we will generate SSH keys for two servers and exchange the keys in order to establish a trust relationship between them.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Generate a Key Pair on Client1
  1. Generate a key pair ( and id_rsa) on Client1 (
    ssh-keygen -t rsa
Authorize Client1 to Trust Itself
  1. Run the following command on Client1:
    cat /home/cloud_user/.ssh/ >> /home/cloud_user/.ssh/authorized_keys
  2. Verify that the authorization was successful.
    ssh cloud_user@
Copy the SSH Key to Server1
  1. From Client1, retrieve the hostname of Server1.
    ssh hostname 
  2. You should be prompted for the cloud_user password.
  3. Copy the SSH keys to Server1 to establish trust between the two devices.
    scp -r /home/cloud_user/.ssh*

    Note: In a real environment, using secure copy (scp) is not best practice, as the private key should not be shared with multiple servers. In your own environment, I recommend using the ssh-copy-id command to only copy the public key, as that’s all that’s needed. But for the purposes of this lab, we’ll use the above command.

  4. Verify that the trust relationship has been established.
    ssh hostname
  5. Run the following two commands on Server1 to verify that the trust relationship has been established:
    ssh hostname
    hostname && ssh hostname

Additional Resources

You have been tasked with finding a way for your organization to run its scripts from the master server without having to save the root password in those scripts. During your research, you find that this can be done by creating a trust relationship between all servers by sharing an SSH key.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?