简体   繁体   中英

AWS_EC2 ssh Permission denied (publickey)

Ugh, so I've read every SO solution and nothing has worked.

Long story short, apple reformatted my computer and I lost my Private key to ssh into my aws ec2 linux instance. I generated a new key, changed the permissions to 400 and tried to ssh but I'm getting:

Permission denied (publickey).

when i use the -v option I'm seeing:

ssh: Could not resolve hostname [path-to-my-new-pem]: nodename nor servname provided, or not known

any ideas?

when you say that you generated a new key, you still need to import the key pair into the EC2 instance, which obviously you cannot since you lost the current private key. ok so how to move it from there.

You need the key pair to be uploaded into the ~/.ssh/authorized_keys

The procedure is explained in amazon doc Connecting to Your Linux Instance if You Lose Your Private Key

basically you need to:

  • create a new key pair from AWS console
  • Stop your current instance (do not terminate as you would loose the current data)
  • detach the current Volume V of the instance
  • Launch a new instance (* specify the same Availability Zone as the instance you'd like to connect to. If you're launching an instance in a VPC, select a subnet in this Availability Zone.*)
  • Attach the volume V to the new instance

--> now you have access to all your data, update the authorized_keys with the new key pair

  • detach again the volume V from the new instance and attach it back to the old instance
  • start the new instance
  • ssh with the new key pair

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM