How to add extra SSH Key Pairs to an Instance

Introduction

When you’re creating an instance, one key pair is added to your instance during launch, so that you can remotely connect using SSH. After you launched your instance, you can add extra SSH key pairs. This tutorial will explain how to add extra SSH key pairs to your instance.

Prerequisites:

Before you begin

Check if your system already has an SSH key pair at the default location by opening a shell, or command prompt on Windows, with the following command:

Linux:

cat ~/.ssh/id_rsa.pub

Windows Command Prompt:

type %userprofile%\.ssh\id_rsa.pub

If you see a file starting with ssh-rsa you already have an SSH key pair and you do not need to generate a new SSH key pair. If you do not see this file, you need to generate a new SSH key pair by using the following guide.

Adding SSH Key Pair:

  1. Copy the contents of your local public key “id_rsa.pub” including the beginning “ssh-rsa”:
cat ~/.ssh/id_rsa.pub
  1. Open the terminal and make an SSH connection with the (Ubuntu) instance.

  2. Edit the “authorized_keys” on the instance and paste the contents of your clipboard below any other keys in that file:

nano ~/.ssh/authorized_keys
  1. Save with Ctrl+O and exit the file with Ctrl+X.

  2. Exit the SSH session by using the command exit.

  3. Try logging back into your instance to confirm it worked. If it did not ask for a password, then it worked.

Conclusion

You now have added an extra key pair to your instance so that multiple users can log in using SSH.