π Generating and Using a New PEM Key for EC2
1. Create a New Key Pair
In the AWS Console:
- Navigate to EC2 β Key Pairs.
- Create a new key pair and download the
.pem
file to your computer. (e.g.,new_pemkey.pem
)
2. Secure the Key
Run this command to set the correct permissions:
chmod 400 new_pemkey.pem
- Generate the Public Key Use ssh-keygen to generate the public key from the .pem file:
ssh-keygen -y -f new_pemkey.pem
Copy the output β this is your public SSH key.
- Add the Public Key in the EC2 Instance Open the EC2 instance in the AWS browser console.
Connect via the browser-based SSH client.
Inside the instance, open the authorized_keys file:
vi ~/.ssh/authorized_keys
Paste the public key you generated in Step 3.
Save and exit.
- Connect Using the New Key Now you can connect to your EC2 instance from your local terminal:
ssh -i new_pemkey.pem ec2-user@<your-ec2-public-ip>
β Youβve successfully created, secured, and configured a new PEM key for your EC2 instance!
Top comments (0)