I did this:

try:
    ec2.get_all_key_pairs(keynames=[key_name])[0]
    print 'Key pair %s exist'%key_name
except ec2.ResponseError, e:
    if e.code == 'InvalidKeyPair.NotFound':
        print 'Creating key_pair %s'%key_name
        key = ec2.create_key_pair(key_name)
    else:
        raise

And as you can see, I created a key_pair, but forgot to save it =( Than I launched instance and realized that I don't have .pem file on my computer, is there any way to recreate it?

有帮助吗?

解决方案

  • mount the root disk of this instance to some other (test) instance.
  • go to folder/home/ec2-user(or other)/.ssh directory.
  • you should have any private key file on your local system,
  • then create/export openssh public key from that new private key file and replace the PublicKey file with authorized_keys (change permissions, ownerships, etc)
  • unmount that old instance disk & then start the instance.
  • now try to connect with new ppk file.

Have a nice luck..

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top