How to Add an Additional Public Key to an Existing Instance on OCI

You may want to access an existing instance from another client machine that has a different public/private key pair on Oracle Cloud Infrastructure. I looked around the net and I could not find a solid documentation on how to do it. Basically, the OCI console itself does not have a support to add another public key.

I thought of my previous post on passwordless SSH article. Basically, you are adding public key to ~/.ssh/authorized_keys so that whoever has the public key in the list can SSH into it. I tried adding a new public key to ~/.ssh/authorized_keys on an existing instance and it was successful. I will describe the steps below.

  1. On a new client machine, execute ssh-keygen to generate a new public/private key pair. If you have already done it, you can skip this step.
  2. It generates ~/.ssh/id_rsa (private key) and ~/.ssh/ (public key).
  3. Print the public key on your terminal by executing cat ~/.ssh/
  4. Copy the public key to the machine that you already have access to the instance. You could email it to yourself or use something like DropBox.
  5. SSH into your existing instance.
  6. Open authorized_keys file. vim ~/.ssh/authorized_keys
  7. Copy the new public key and paste it in the last line.
  8. Save the file and exit vim. (:wq)
  9. Go back to the machine where you generated the public key.
  10. SSH into the machine now and you now have access to the instance.

This method probably can be applied to other cloud services as well as long as you have a Linux distro instance.

Leave a Reply

Your email address will not be published.