Connecting to AWS EC2 linux instance using keypair(pem) file

Once you launch your ec2 Linux instance, make sure that the two status checks are done and turns green under the instances option of EC2 dashboard. This implies that the Linux machine is fully setup and is ready for work. Ensure that your instance allow inbound traffic for SSH(22 port) from security group.Before connecting to the instance, have two software’s clients installed on your PC namely PuTTY, a free SSH client for Windows. and Puttygen(to convert .pem to .ppk file). AWS doesn’t allow to connect to the EC2 Linux Instance directly using .pem file. you need to convert the .pem key pair file to .ppk format so that it can be used with PuTTY. You need to generate a .ppk file using the free Puttygen tool from the .pem key pair file of respective Linux machine instance.

Generating .ppk file using Putttygen:

Open Puttygen tool and click on Load. Next select all files under file type and try to locate your .pem file for the keypair which is associated with your linux instance.  Open that file and click OK.

Make sure that type of key to generate is set to SSH-2 RSA.

Click on Save private key To save the file in .ppk format so that it can be usable by putty.

PuTTYgen displays a warning about saving the key without a passphrase. Click YES

Important note to be kept in mind is to save the .ppk file with the same filename as .pem. (extension wil be added automatically)

Now we are good to go with establishing putty connection to linux instance from windows using Putty SSH client.

Putty Connectivity:

Open your Instances page on AWS EC2 console and select the appropriate Linux instance and note down the Public Dns name or Elastic IP if you have assigned already.

Open Putty Client and expand the tree as Connection SSH -> Auth. Under category pane on left side. Make sure that the screen looks like below



As in above screenshot, click on browse and locate the .ppk file which you have generated using Puttygen.

Now open open the sessions option under category pane and enter the host name.

There is a standard format in which it has to be entered in hostname textbox to connect to instances on AWS. The format is user_name@public_dns_name.Or user_name@elasticip.

General usernames for the instances will be has below:

  • For an Amazon Linux AMI, the user name is ec2-user.
  • For a RHEL5 AMI, the user name is either root or ec2-user.
  • For an Ubuntu AMI, the user name is ubuntu.
  • For a Fedora AMI, the user name is either fedora or ec2-user.
  • For SUSE Linux, the user name is either root or ec2-user.

Otherwise, if ec2-user and root don’t work, check with the AMI provider(generally will be mentioned under usage guidelines tab of your marketplace or instances page)

Next, make sure connection type is SSH and port number is 22.

Click on open. If you are connecting for the first time, putty displays a security alert, just click OK.

Next a window with command line is opened and it will automatically authenticate to the machine with the given username.

If you encounter with any errors in above process, click here to troubleshoot.