Quantcast
Channel: Cloud Training Program
Viewing all articles
Browse latest Browse all 1906

Oracle Cloud (OCI): How To Recover SSH Keys In Compute Instance

$
0
0

This post covers the Steps for Recovering the SSH Keys in Compute Instance Oracle Cloud Infrastructure (OCI). 

To know more about Compute in Oracle Cloud Infrastructure, please check our previous post on  [Video] Oracle Cloud Infrastructure (OCI) | Compute CPU & Memory

Note:  An SSH key pair comprises of a private key and public key. You keep the private key on your computer and provide the public key every time you launch an instance.

Typical Scenarios When you need to recover your SSH Keys

  • If you get a Permission denied (publickey,gssapi-keyex,gssapi-with-mic)” error when trying to connect your instance via putty in windows or terminal in Linux.
  • Imagine you are trying to connect into your Oracle Cloud Infrastructure instance but either you forgot which key you used or, for some unknown reason, your OPC user SSH key got corrupted or deleted.

Process to Follow

Step 1: Stop the compute instance for you are to recover your ssh keys. In the Oracle Cloud Infrastructure Console, go to the details page for the instance and click Stop

Instance Page

Step 2: Detach the boot volume. In the Boot Volume section, click the Actions icon and choose Detach.

Navigate Block Volume

Block Volume Detach

Step 3: Attach the boot volume to another Linux instance by going to the details page of a different VM, clicking Attach Block Volume, and then selecting the boot volume that you just detached in the previous step. Be sure to select Read/Write access.

Block Volume Attach

Step 4: After the boot volume attachment is completed (the BV icon is green), connect through SSH in the running VM and run the iSCSI commands to make that new disk available and visible by the OS.

iSCSI Commands

Your boot-volume should appear as /dev/sdb.

BootVolume

  • Make /dev/sdb3, which is the root (/) partition where you can recover the OPC SSH key file, available to the local operating system using “mount” command. Be sure to use the -o nouuid option; otherwise, you will see the “mount: wrong fs type, bad option, bad superblock on /dev/sdb3” error message.

$ sudo mount -o nouuid /dev/sdb3 /mnt

  • Fix the OPC SSH key by editing the /mnt/home/opc/.ssh/authorized_keys file and adding your SSH key public file.

$ sudo vi /mnt/home/opc/.ssh/authorized_keys

  • After you add or change the SSH public key you need to use, save and exit it.
  • Run umount /mnt.

$ sudo umount /mnt

Step 5: Detach the iSCSI boot volume by running detach iSCSI commands.

Detach

Step 6: Ensure that the /dev/sdb disk is no longer available or visible through the SSH connection and then detach it.

Step 7: Reattach the boot volume to the instance where you wanted to recover the SSH key, wait for it to become operational (green icon) and start it.

Reattach Boot Volume

That’s it. You recovered your OPC user SSH key and you can now able to connect to your compute instance for which you are recovering your ssh keys.

Now, it is your turn to try this Solution & If you face any issues then post your doubts in the comment section!

Related/Further Readings

Next Task For You

if you want to take your career to next level by becoming Oracle Certified Cloud Architect even if you are a beginner then Join FREE Masterclass on How To Become Oracle Certified Cloud Architect [1Z0-932] in 8 Weeks 

Click on the image below to register for FREE

Register this FREE Masterclass to Become Oracle Cloud Certified

The post Oracle Cloud (OCI): How To Recover SSH Keys In Compute Instance appeared first on Oracle Trainings.


Viewing all articles
Browse latest Browse all 1906

Trending Articles