Skip to main content

Background

When you have created and launched an AWS Linux Elastic Cloud Compute (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

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.
This image shows the AWS EC2 Management Console.
Image Caption

The AWS EC2 Management Console.

This image shows how to connect to your Instance window
Image Caption

Connect To Your Instance window

cd ~/<path to pem_folder>

Example:     $ cd ~/Downloads

To view the contents of a directory:

ls -ltr

   3.  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

   4.  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.

   5.  Paste the string at the Terminal prompt

  • Delete the double-quotes enclosing filename.pem
  • Press Enter

   6.  Type “yes” when prompted “Are you sure you want to continue connecting?”

  • Press Enter
  • A terminal window appears for your EC2 instance.
This image shows how to copy commands from the Connect To Your Instance window
Image Caption

Copy commands from the Connect To Your Instance window

This image shows the confirmation window indicating when you are connected to your EC2 Instance
Image Caption

You are now connected to your EC2 Instance.

Move Data into an EC2 Instance

Important: The commands described in the “Move Data into an EC2 Instance” and “Move Data Out of an EC2 Instance” sections are run from your Mac computer.

Move a file (for example, a file to be processed) from your computer to your EC2 Instance Home directory of user ubuntu using SCP (secure copy protocol).

At the Terminal prompt of your Mac OS computer:

scp -i private.pem your_filename
ubuntu@EC2instance_public_DNS:/home/ubuntu/

  1. Example of moving file S1A_EW_GRDM.zip from your computer to your EC2 Instance: 
    scp -i AWSrecipe.pem S1A_EW_GRDM.zip ubuntu@ec2-52-89-147-172.us-east2.compute.amazonaws.com:/home/ubuntu/
  2. Command syntax: < indicates optional input>
    scp -i pemfile.pem your_filename ubuntu@Public_DNS://

Move Data Out of an EC2 Instance

Move a file (for example, a processing product) from your EC2 instance ubuntu directory to your computer using SCP (secure copy protocol).

At the Terminal prompt of your Mac OS computer:

scp -i private.pem ubuntu@Public_DNS:/home/ubuntu/filename ~/local_folder

  1. Example of moving file F2_unw_phase.tif from your EC2 Instance to your Mac computer Downloads folder: 
    scp -i asf_aws.pem ubuntu@ec2-52-89-147-172.us-east2.compute.amazonaws.com:/home/ubuntu/PRODUCT/F2_unw_phase.tif ~/Downloads
  2. Command syntax: < indicates optional input>

scp -i pemfile.pem ubuntu@PublicDNS://your_filename ~//local_directory

Note: If you store your .pem file in a directory other than the directory you are working in, you must provide a path for that directory in the SSH command.

Example:

ssh –i ~/Documents/aws_pem/asf_hauer.pem ubuntu@ec2-54-69-135-138.uswest-2.compute.amazonaws.com

Note: If you Stop your instance using the EC2 Management Console (Action > Instance State > Stop), when you restart it, you will be assigned a new Public DNS.

Use this new DNS to reconnect. (See Connect to an EC2 Instance using SSH — Step 4)

This image shows the Instance State navigation
Image Caption

Instance State navigation

Details

Last Updated

Published on

Data Centers

Alaska Satellite Facility DAAC (ASF DAAC)