How to connect to AWS Compute using private key (.pem) from Ubuntu 16.04

Managing AWS Compute (EC2 or LightSail) instance from Ubuntu 16.04 is a bit tricky for newbie like me. Even the AWS instance has SSH enabled, we cannot use ordinary ssh command to connect to the instance. This is because Amazon instance is protected with more secure ways. So, we need a key pair or private key (.pem) in order to connect to the instance. The private key itself can be created from the AWS Console.

amazon keypair.png

The keypair can be downloaded (.pem) and we will need this file in order to connect to our instance.

To connect to an instance, we need the following items:

  • private key pair (.pem)
  • IP address of the instance

Steps to connect to AWS Instance using keypair

A. Download the keypair 

B. Change the permission

We need to change the keypair permission. If not, you will get the following error:

dhani@dhani-ThinkPad-T450:~/Downloads/AWS_LightSail$ ssh -i AWS_LightSail_01.pem ubuntu@34.202.14.229
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0664 for ‘AWS_LightSail_01.pem’ are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key “AWS_LightSail_01.pem”: bad permissions
Permission denied (publickey).

So we need to change the .pem file permission. Use this command instead

sudo chmod 400 yourkeypair.pem

C. Connect via SSH

Use this command to connect via SSH

ssh -i AWS_LightSail_01.pem ubuntu@34.202.14.229

Don’t forget to change the IP address, username and the keypair with yours. Thanks.

Admin

Leave a Reply

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