RSS
people

My Experiments with AWS – 2 : Connect to EC2 instance

In order to connect with an ec2 instance there are three prime prerequisites:

  • The key file (.pem extension) created while launching an EC2 instance in AWS.
  • Port 22 of the instance is open while launching the instance.
  • Know the public DNS of your EC2 instance.

Key File:

Read Basics of AWS and how to launch an EC2 instance for steps for the the above mentioned. If you have lost your .pem file – there is no way (that I know of) to recover it back. But, you can always terminate your instance and start a new instance all over again.

Open Port 22 (Security Groups):

If your port 22 was not open – you can use the aws console to make changes to the “Security Group” and allow port 22. Do the following:

  1. Login to AWS console, open EC2 tab, select appropriate region and click on instances.
  2. You will see a table of your instances. Notice the column named “Security Groups”. Every machine belongs to some security group which is nothing but a set of rules which allows you to control port access from specific IP range.
  3. Now click on “Security Groups” on the left sidebar under “NETWORKING & SECURITY” heading. 
  4. Click on the security group name – you want to change. Please note that in a multiple machine scenario – you will have different kind of security groups. For example: for webservers – open port 80 from all IPs. For internal mysql servers – open port 3306 for internal IPs etc. If you have only one machine in default security group – you may want to keep port 22 open for SSH and if you plan to use this as webserver as well – open port 80 too.

Know Public DNS:

Every EC2 instance has a public DNS, private DNS and private IP address associated with it. The public DNS is required when you want to connect to your instance from outside. To get the public DNS: Click on “Instances” on sidebar of aws console and select the ec2 instance. The bottom part will show many information including security group and public/private DNS. (Screenshot below)

Now that we have all things in place – we can login to the EC2 machine using:

# put your keyfile name instead of keyfile.pem.
# replace ec2-xxx-xxxx-x-xx-amazonaws.com with your public dns
ssh -i keyfile.pem ubuntu@ec2-xxx-xxxx-x-xx-amazonaws.com

Please note that the user ubuntu is automatically created if you select the ubuntu AMI mentioned earlier. (I will always assume the ubuntu image – if not mentioned). If you use some other AMI – check the default user name. Amazon’s AMI have the user name as ec2-user. So, your command may look like:

ssh -i keyfile.pem ec2-user@ec2-xxx-xxxx-x-xx-amazonaws.com

One Response to “My Experiments with AWS – 2 : Connect to EC2 instance”

  1. Webkoof » Blog Archive » My Experiments with AWS – 3 : lamp server, Elastic IP, DNS for ec2 Says:

    [...] chart yahooAug 01 2011My Experiments with AWS – 3 : lamp server, Elastic IP, DNS for ec2Now that we can connect to the ec2 instance – we want to setup a basic website. I use ubuntu AMI – so, following instructions are [...]

Leave a Reply