ssh-aws-ec2-instance

How to SSH into AWS EC2 instance

Once you’ve launched an EC2 instance on AWS, the next step is to connect to it. Secure Shell (SSH) is the most common way to access your Linux-based EC2 instances directly from your terminal. In this guide, we’ll learn how to SSH into an AWS EC2 instance using the .pem key file provided during setup.

Step-by-step guide to SSH into AWS EC2 instance

Step 1. Locate your .pem key file

The .pem key file is generated when you create your EC2 instance and download your key pair. You should ideally have it saved and need to locate it first. It will look something like:

my-key.pem

It’s important to note that you’ll need this file to authenticate via SSH. If you’ve lost it, you cannot recover it and must create a new key pair and instance.

Step 2. Change the permissions of your .pem file

Next, you need to set the correct permissions for your .pem file so that only you can access the key. You can do that by running the following command in the terminal:

chmod 400 my-key.pem

Step 3. Find your EC2 public IP address

Now, you need to find your public IP address. To do this, go to your EC2 Dashboard and then Instances.
Here, locate your instance and copy the Public IPv4 address. It should look something like this:

3.125.174.XX

Step 4. Connect to your EC2 instance

Now, use the ssh command to connect it to your EC2 instance. Here’s a sample command:

ssh -i my-key.pem ec2-user@3.125.174.XX

Step 5. Accept the prompt

If it’s your first connection, you may see a message like this:

Are you sure you want to continue connecting (yes/no)?

Type yes and press Enter. Once you do that, you’ll then be logged into your EC2 instance.

Pump saves ~60% on CLOUD *for free*

FAQ

Get started with PUMP for free

No contracts, no credit card needed to sign up

Get started with PUMP for free

No contracts, no credit card needed to sign up

Get started with PUMP for free

No contracts, no credit card needed to sign up

1390 Market Street, San Francisco, CA 94102

Made with

in San Francisco, CA

© All rights reserved. Pump Billing, Inc.