cloud-recipe-image-1

How to Connect to EC2 with SSH Mac OS X


Background

When you have created and launched an AWS Linux EC2 instance, you need to be able to connect to it from your computer using the SSH protocol. This data recipe will use the Mac Terminal window command line.

Prerequisites

  • You must have an AWS account. If you don’t have an account, create one now.

Note: You will need to provide credit card information for your new account.

Connect to an EC2 Instance using SSH

    1. In the AWS EC2 Management Console, click on Instances in the left menu (1) under EC2 Dashboard.
      • Click on the Connect button (2) to open the Connect To Your Instance window.
      • You will copy and paste information from this window to your Mac Terminal window later.
    2. Next, open a Terminal window on your Mac and navigate using the cd (change directory) command to the folder containing the private key file (.pem) created during the EC2 configuration process. This is usually in the Downloads folder unless you moved the file to another folder.
The AWS EC2 Management Console.
Connect To Your Instance window

cd ~/<path to pem_folder>

Example:     $ cd ~/Downloads

To view the contents of a directory:

ls -ltr

    1. Change access permissions for the private key file (.pem)
      • At the Terminal prompt, type:

chmod 400 <filename.pem>

    • Or copy the command (1) from the Connect To Your Instance window and paste at the Terminal prompt.
    • Press Enter
    1. From the Connect to Your Instance window, copy the complete SSH command under Example: (arrow 2)
      • This string includes your filename.pem, the username ubuntu, and the Public DNS of your EC2 Instance.
    2. Paste the string at the Terminal prompt
      • Delete the double-quotes enclosing filename.pem
      • Press Enter
    3. Type “yes” when prompted “Are you sure you want to continue connecting?”
      • Press Enter
      • A terminal window appears for your EC2 instance.
Copy commands from the Connect To Your Instance window
You are now connected to your EC2 Instance