Monday, February 19, 2018

How to connect to an EC2 instance from your local machine after creating EC2 in AWS? | Connect to AWS EC2 instance from your local machine

Let us see how to connect to an EC2 instance running in AWS from your local machine.


1. Keys(for e.g., yourkey.pem) already downloaded in your local machine, preferably in Downloads folder.
2. EC2 instance is up and running
3. For windows laptop, you need to install Git by downloading from this URL - For Apple laptop you need to download iTerm from here.

Steps to connect to your EC2 instance:

1. Go to AWS console.
2. Click on EC2, click on running instances link

3. Select the checkbox of EC2 you would like to connect to.
4. Click on Connect or Action, Connect. Under SSH client.
Copy the url from SSH which looks like below:
For e.g.
ssh -i "mykey.pem"

Watch the steps in YouTube channel:

Windows Laptop instructions
5. Go to your local machine, Open Git Bash in Windows

make sure you are in downloads directory where your keys got downloaded. Type the below commands:

type below commands: 
this should tell you which directory you are and then navigate to downloads dir.

cd  ~/downloads 

Now copy the value from Example in the above screen

ssh -i "mykey.pem"
and then type enter, say yes and enter

Mac Book Laptop or iMac Instructions

Open iTerm window, type the below command to go to downloads directory.
cd downloads

For few Mac laptops, it may add .txt in the end of pem file. in that case you need to remove .txt in the end

and then execute below commands to make sure you are not making keys publicly viewable. 

chmod 400 *.pem

6. Paste the url from example highlighted above in step # 4.
ssh -i "mykey.pem"
7. type yes when it is asking to connect.
8. now you should be in AWS cloud, screen should show something like this, It means you are successfully connected to EC2 instance running on AWS cloud.



  1. The first lab exercise completed

  2. Very helpful, thank you.

  3. Hi
    Thanks for sharing awesome information.
    1. I have an aws ec2 ubuntu instance ,it installed with jenkins master
    2. I want to create a slave(local linux machine) machine to jenkins master and copy the latest successful build binaries using shell scripts and then execute the automation script jobs.

    Please guide me on the above is appreciated

    Thanks in advance

    1. Thanks for your response. Could you please use the below url for master/slave. Instead of setting up slave on aws, you can setup on your local machine.

  4. thank so much for the step by step document. it helped me

  5. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. mining dump truck price

  6. One question...
    how to connect to your localhost running on windows instance on aws.

    is accessible on aws server.

    But not working if selected from local pc

  7. This Lab is so helpful
    First time getting on it and it was highly self explanatory