Part 2: Create an instance on EC2 and connect via ssh from local Mac

This time, we’ll ssh connect to an instance created on EC2 from a local Machine.
Go to Part 1 for creating a instance on EC2.

  1. Download a “pem” file that you can download when you create an instance on EC2. (In this tutorial, we downloaded it to “Download” folder)
  2. You wanna copy this pem file to ~/.ssh folder, but this is just an optional. To do so, open a terminal on Mac, and type
    cd ~/.ssh
    cp ~/Download/downloaded-from-EC2.pem any-name.pem
    From here, we'll use the copied pem file (ex. development.pem)
  3. Go to EC2 site, and check IP address of the instance that you created on Part 1.
  4. Now you should be able to access to the EC2 server. As an example, if you haveIP address on EC2 : 50.123.456.7
    Pem File: development.pem

    ssh -i development.pem ubuntu@50.123.456.7

    As we chose Ubuntu as an Operating System, the default root user is “ubuntu”. This might change depending on Operating System.

  5. Congrats! Now you should be in the EC2 Instance.
  6. For later use, you can modify ~/.ssh/config so that you can make ssh connections easier.
    cd ~/.ssh
    sudo vi config # enter password 

    and write something like

    Host dev
    IdentityFile ~/.ssh/development.pem
    User ubuntu

    Now, you can ssh access by typing

    ssh dev

Leave a comment