Experience: is what you get soon after you need it.

Experience: is what you get soon after you need it.

****************Got the opportunity to pen a Book on Database Cloud Services.......More details to follow.***************

Title : Database Cloud Revealed
Publisher : Apress
Release Date : Jan-2021

**********************************************************************************


My Cloud Certifications:

AWS Certified Solutions Architect Associate

Azure Certified Architect Expert

Azure Certified Architect

Azure Certified Administrator

Oracle Cloud Infrastructure 2018 Certified Architect Associate.

Oracle Cloud Infrastructure Classic 2018 Certified Architect Associate.

Oracle Database Cloud Administrator Certified Professional.

Oracle Database Cloud Service Operations Certified Associate.

Search This Blog

Thursday, June 11, 2020

How to update ssh key on a cloud VM

It happens that someone created a VM with a key and either that person isn't there anymore or forgot to share the key with others or somehow lost the key altogether. Whatever the case might be in the below blog post you will see how to update the ssh key in order to login into the VM.

For AWS:

Generate new key pair with your favorite tools.
Ex:- using openssh

samshaik@shaikprod:~$ ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/samshaik/.ssh/id_rsa): cloud-key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in cloud-key.
Your public key has been saved in cloud-key.pub.
The key fingerprint is:
SHA256:GJk8yaVsFSNxquyVLwmR6uGMxzslniA0TMQ1Ib9AO8g samshaik@shaikprod
The key's randomart image is:
+---[RSA 2048]----+
|o+.+. o.*.       |
|+o+ .= @ .       |
|+E .o &          |
| +oo.+ =         |
|. +.+ + S        |
|o*.o.o o         |
|oo*+. o .        |
| .+.   .         |
|  ..             |
+----[SHA256]-----+


Now this will create two keys (public/private) in the specified path.

samshaik@shaikprod:~$ ls -lrt ~/.ssh/cloud-key*
-rw------- 1 samshaik samshaik 1766 Jun  9 14:44 /home/samshaik/.ssh/cloud-key
-rw-r--r-- 1 samshaik samshaik  400 Jun  9 14:44 /home/samshaik/.ssh/cloud-key.pub


1) Now stop the VM
2) Include the below code snippet in the user data dialog box as follows:
Select instance --> Actions --> Instance Settings then choose View/Change User Data

Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0

--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
cloud_final_modules:
- [users-groups, once]
users:
  - name: username  (name of the user you want to change the key for ex:-ec2-user)
    ssh-authorized-keys: 
    - PublicKeypair (No quotes required and make sure you have dash at the begining)

For AWS:



3) Start the instance
Now try ssh into the instance using the updated key.


Azure:

In Azure select the VM from the left menu --> Support + Troubleshooting --> Reset Password

Here you can either create a new user/update existing user password or ssh keys










































In Oracle Cloud:









No comments: