Ask Your Question

Is it possible to associate key-pair at VM runtime?

asked 2015-10-19 00:33:22 -0500

Nodir gravatar image


I know It is possible to associate key-pair during VM boot. I was wondering if it is possible after VM boot as well (during runtime). My understanding is that cloud-nit (running inside VM) fetches key-pair from metadata service and injects to the VM. Is possible to trigger this mechanism after boot, as well? It is very useful feature to have.



edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-10-23 07:48:57 -0500

Vinoth gravatar image

Openstack have no option to inject keypair after the VM is created. But we can try in another way if we have access to hypervisor (KVM).

login into the compute node where your VM is running.

       $ virsh list
       $ virsh suspend <vm id>
       $ cd /var/lib/nova/instances/<instance id folder>
       $ qemu-nbd -c /dev/nbd0 `pwd`/disk
       $ mount /dev/nbd0p1 /mnt/

       $ cp ~/.ssh/ /mnt/ubuntu/.ssh/authorized_keys
       $ umount /mnt
       $ qemu-nbd -d /dev/nbd0
       $ virsh resume 30

Now you could use this as your keypair.

P.S:- I never tried this method yet :-)


edit flag offensive delete link more


Thanks, Vinoth!

I don't think manually mounting VM volume for keypair injection is an ideal solution. But I'll give it a try see if it actually works.

Nodir gravatar imageNodir ( 2015-10-23 12:03:44 -0500 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools



Asked: 2015-10-19 00:33:22 -0500

Seen: 148 times

Last updated: Oct 23 '15