Ask Your Question
0

Can we add/replace new keypair in a running VM?

asked 2018-02-27 01:39:37 -0600

udayutkarsh gravatar image
 I have a running VM with keypair injected at the time of creation. But I cannot find the ssh-key.pem file that was generated then. I do not have user/pass to log in. We used to log in only using .pem file. Is there any way to recover the .pem file or create new one and inject into vm?
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2018-02-27 04:10:54 -0600

The term "injecting" is misleading. What actually happens: Nova provides the keypair in the metadata server or config drive, and the instance retrieves it from there when it boots up.

There is no command or API to add a keypair to a running instance. You could add a metadata item that contains the public key to a running instance, but this is pointless if the instance doesn't regularly check available metadata. The usual cloud images don't do that; you would have to create your own image. Which doesn't solve your acute problem.

Assuming your instance is implemented with libvirt rather than Hyper-V, VMware or another hypervisor, you could access its filesystem with a tool like guestmount or guestfish and set a root password or add a key. Where that filesystem is located depends on how you started the instance - ephemeral storage with a qcow2 file for backup, ephemeral storage with a raw file for backup, volume as root disk etc. Before you modify the filesystem, be sure to freeze the instance or shut it down.

edit flag offensive delete link more
0

answered 2018-02-27 03:29:40 -0600

Deepa gravatar image

There are so many links you could refer here ..Few are below

https://ask.openstack.org/en/question...

https://ask.openstack.org/en/question...

https://ask.openstack.org/en/question...

https://ask.openstack.org/en/question...

If nothing works What you could do is take a snapshot, boot a new instance from that snapshot, and specify a key to get injected.

Best of luck !

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2018-02-27 01:39:37 -0600

Seen: 509 times

Last updated: Feb 27