Adding Public SSH key in Oracle Cloud Infrastructure Gen 2 !!

Hi Guys,

In today’s post, will see how to add new public key to the OCI instance which was already created.

Followed the document https://docs.cloud.oracle.com/iaas/Content/Compute/References/serialconsole.htm

High-level Steps:

  1. Create a new pair of Public and Private key pair require to upload using PUTTYGEN.
  2. Install Git or if you have a linux server, go the server and by using ssh-keygen create the public and private key which will be used in the console connection of the OCI instance.
  3. Now, go the OCI instance and click on console connection and create a one using the public key generated in Git or linux server.
  4. Once, the console connection is active, click on connect SSH, copy the command and paste in the Git or linux server.
  5. After pasting the command supply the password of the key and it will connect remotley to the OCI instance.
  6. Now, go to OCI instance GUI, reboot the system and edit the kernel to start in bash prompt.
  7. Once you get in to bash prompt edit the authorized keys of the OPC user and restart the machine.
  8. After restarting machine try to connect with the private key(which was assoicated with public key generated through PUTTYGEN) it should have to connect successfully.

Steps:

Using the below link, please create key pair using PUTTYGEN.

https://www.oracle.com/webfolder/technetwork/tutorials/obe/cloud/compute-iaas/generating_ssh_key/generate_ssh_key.html#section1

Below is my instance to which I upload the new key:

In my case I’m using a Linux test server instead of Git and try to create the keys to create console connection.

Once console connection is active, click Connect with SSH and copy the command to execute in linux test server.

Successfully connected remotely to the OCI instance.

Reboot the OCI instance.

Select the kernel and hit ‘E’ to edit the kernel to run with bash prompt.

Editing the kernel using = rw init=/bin/bash and press ctrl+x, which it will land on bash prompt.

Execute the below commands and update the new public key generated through PUTTYGEN to authorized_keys

Copy the new key to the authorized_keys file save it.

Change the ownership and permissions of authorized_keys file and reboot the system.

Now, connect to OCI instance with new private key, it should have to connect successfully.

Hope this post find’s you well !!

Happy learning !!

Firoz Hussain K.

Add Your Comment