I have an Amazon OpsWorks stack with EC2 instances. Now it has Default SSH key (.pem) which I have no access to. What I've tried:
chmod 600
.ssh -v -i path/to/.pem ubuntu@host
after restarting it: permission denied (public key)
Stack Settings
page after restarting the whole stack: still getting permission denied (public key)
ubuntu
to ec2-user
. Still nothing!Noticed that keys changed at OpsWorks Home but remained the same at EC2 Management Console. Strange.
Am I missing anything? Doing wrong? Any help appreciated. Thanks
Like @chris said, there is no way to change the key associated with the instance. You will need to launch a new one with the new key assigned to it.
BUT If SSH access is what you need, don't bother trying to change or update the key associated with the instance. It has been a while since I stopped assigning keys to instances over allowing OpsWorks manage user access in the permissions section.
This gives you great flexibility because you don't need to share keys amongst users or start new instances every time you need to change or set a new SSH key. You can add or remove users any time, and you control who has SSH and/or Sudo access.
To start either grant one of your users access to OpsWorks or import IAM users:
After access has been granted, ask the user to add their own public key in the "My Settings" > Edit page:
If you gave this user access to SSH all you have to do is wait for the recipes to finish running and the user will be able to connect to the instance like this:
$ ssh -i ~/.ssh/[your-key-file] [user-name]@[instance-ip-address]
Note that any time you make changes to the permissions or settings section, recipes will be run in your instances updating the user access.
For more information on how to grant user permissions in OpsWorks see the AWS Documentation