Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I understand the concept of "ssh keys" to login to a server without entering a password, however, I am not understanding how/what PEM key files are to log in to EC2 instances.

In the AWS console, I can generate or import a PEM key, but where/how do I use this file on my laptop to login to cloud instances?

Thanks for help!

share|improve this question
up vote 3 down vote accepted

Or you can create an entry on your .ssh/config as follows:

host myserver
user username
IdentityFile path/to/your.pem

So after that you can ssh to your server like this: ssh myserver

According to PEM files, it's also good keep a copy in a safe place as it can not be regenerated.

share|improve this answer

from command line, just like this:

$ ssh -i yourpemfile.pem

Then you can login to the server.

share|improve this answer

The other answers here are great, assuming that the destination server already has the .pem file's public key. In my case, I created a .pem file to access an existing server, which was not configured for my newly generate key. So here is how I managed to set up my server for access using my newly created .pem key:

Create the public key from the .pem file: ssh-keygen -y -f my-new-key.pem >

Transfer the key to my server: scp -i ~/.ssh/my-old-key.pem /path/to/ user@123.456.789:~/.ssh/

SSH into the server and attached the pem file as follows: ssh -i ~/.ssh/my-old.key.pem user@123.456.789 and run cat ~/.ssh/ >> ~/.ssh/authorized_keys

Now, you can ssh into your server using your newly generated .pem key! ie ssh -i ~/.ssh/my-new-key.pem user@123.456.789.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.