Created
April 15, 2015 19:12
-
-
Save plasticbrain/6632b57bbf6a97e6a02b to your computer and use it in GitHub Desktop.
AWS - EC2 - Change PEM Key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. From the AWS EC2 Console go to "Key Pairs" and generate a new key pair (eg: NewKey.pem); Download the generated pem key, and chmod it to 0666 | |
2. Use the new pem key to generate a public key | |
$ ssh-keygen -y | |
When prompted, enter the path to NewKey.pem. This will generate NewKey.pub | |
Tip: Edit NewKey.pub and append the key's name so you can identify it easier in the next steps. | |
Just append a single space, then a tag/name for the key | |
3. Add the new public key to your instance | |
$ cat NewKey.pub | ssh -i OriginalKey.pem user@amazon-instance "cat >> .ssh/authorized_keys" | |
4. Test the new key by logging in and removing the old/original key | |
$ ssh -i NewKey.pem user@amazon-instance | |
$ nano ~/.ssh/authorized_keys | |
Find the line containing the "original" key and remove it. | |
tnx
Thank you so much, saved my day.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This saved my day! Thank you.