How to SSH to EC2 instance at Amazon AWS

Last updated on August 8, 2020 by Dan Nanni

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).

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.

Once you obtained the public DNS of your EC2 instance, you can SSH to the instance by specifying the private key with -ioption as follows. I assume that the private key for the instance is named xmodulo.pem.

$ chmod 600 xmodulo.pem
$ ssh -i xmodulo.pem ec2-107-22-3-248.compute-1.amazonaws.com

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 do not want to manually specify your private key with -i option, you can use an SSH configuration file to automatically let you use the private key for your EC2 instance.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean