Add keypair to existing Instance

asked 2015-02-19 02:45:02 -0600

LZ gravatar image

A instance was launched without a keypair attach to it.

Is there anyway to attach an existing keypair to an instance that is already launched?


edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2015-02-19 06:33:05 -0600

Vinoth gravatar image

It is not directly possible to add keypair to the VM without knowing its password atleast. But I wont say it's impossible because we can use tool like guestfish to enter into the VHD of VM and do add the keygen file which will reflect in next boot of the VM. But I'm not sure this would work.

Any way lets look at the mainstream possiblities, If you can access the same VM using the password which is possible if you pushed or created the password using the image creation.

Then Follow the steps below:

Let us assume your existing key pair is " openstack_keypair.pem". (Openstack Nova generate keypair as pem file)

Now you have "openstack_keypair.pem" file in your local machine which contains private key information.

We need to generate the public key for existing private key(openstack_keypair.pem). Use the following command to generate public key.

ssh-keygen -y -f openstack_keypair.pem >

This command will create the .pub file in the same directory. You can open the file using your favourite editor and could see the file starts with "ssh-rsa AAAA...". Copy the entire content and we have to place it in the VM that has to be accessed using the keypair.

Now open the VM with the known password and create a file at ~/.ssh/authorized_keys . Open the authorized_keys file and paste the content copied from file.

Save & exit. Now you are set to go.

Cheers, Vinoth

edit flag offensive delete link more

answered 2015-08-09 09:18:36 -0600

If you can not be logged, additional key in any event 's difficulty likely.

I made another way to use the existing key.

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2015-02-19 02:45:02 -0600

Seen: 16,092 times

Last updated: Feb 19 '15