How to ssh to EC2 instance at Amazon AWS

After you have created an EC2 instance at Amazon AWS, you can access the instance via ssh. In order to do so, you need two pieces of information: (1) private key file associated with your instance and (2) public DNS of your instance.

The private key file for your EC2 instance should have become available to you while you went through creating the instance via Request Instances Wizard on EC2 Management Console. During EC2 instance creation, Request Instance Wizard prompts you to choose public/private key pair for your instance (either choose from existing key pairs or create a new key pair).

Create an EC2 Instance on Amazon AWS

When you ssh to your EC2 instance, you need to use the same private key that you downloaded from Amazon EC2. You can download a private key only at the very first time you create a new key pair, and you cannot retrieve it later on. So make sure to store the private key in a safe place.

Next, you need to know the public DNS of your instance. For that, go to EC2 Management Console, and click your instance.

Create an EC2 Instance on Amazon AWS

Once you obtained the public DNS of your EC2 instance, you can ssh to the instance as follows. I assume that the private key for the instance is named "xmodulo.pem".

$ chmod 600 xmodulo.pem
$ ssh -i xmodulo.pem

Changing the access permission of your private key is necessary for ssh access on EC2. Otherwise, you will get the following error.

Permissions 0664 for 'xmodulo.pem' are too open. It is required that your private key files are NOT accessible by others.

If you want, you can use ssh configuration file to automatically force you to use a particular private key to ssh to your EC2 instance, instead of manually specifying the private key using "-i" option.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

Leave a comment

Your email address will not be published. Required fields are marked *