Revision history [back]

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.