This is a post for all those beginners just starting off with AWS. I know how frustrating it is to just get beginner level help in an environment where everyone seems to be a server ops expert.

So let’s discuss how to access your new server via SSH.

Wait, why the heck would a beginner ever SSH into a server?

Believe it or not, now that you’re on AWS, all those server administration tasks that were taken for granted are going to haunt you at every corner. You’ll have a newfound appreciation for what hosting providers do and that pesky cPanel you’ve grown to love and hate.

For example, you may have to change file or folder permissions, restart a service like Apache, or modify something that would typically cost time and money if you enlist a contractor. So be awesome and just try to do it yourself!

So here we go with some basics:

Primary Usernames for EC2 Instances:

I wish someone told me this when I first started playing with AWS. You’ll find these type of treasures hidden in Q&A threads, but not in any easy to understand guide in AWS documentation. Depending on the type of EC2 instance you have setup, below are the default / primary usernames:

  • “ec2-user” (Amazon Linux, Red Hat Linux, SUSE Linux)
  • “root” (Red Hat Linux, SUSE Linux)
  • “ubuntu” (Ubuntu Linux distribution)
  • “fedora” (Fedora Linux distribution)

Identify your Ec2 Instance Name

To SSH into your EC2 instance, you’ll need to grab its the EC2 Public DNS URL. It will look something like below:

To find this Public DNS URL, do the following:

  1. Login to AWS Console – In or Create an AWS Account
  2. Click on Services on the nav menu, and then select EC2. Click on the Running Instances link
  3. Select the EC2 Instance and make note of the Public DNS URL. That will be the URL you will use to SSH into the server.
EC2 Management Console - Learn how to SSH to EC2 Instance on AWS
Click for larger image

Commands to SSH into EC2 Instance:

Next, let’s get to actually logging into your EC2 instance. To do so, you’ll have to open Terminal (on a Mac), or a SSH client like Putty (if on PC). Then, use the command below based on the type of instance you have. Pay attention to the difference in the primary username.

If Amazon Linux or Red Hat Linux EC2 instance:

ssh -i path/to/AccessKey.pem

If Red Hat Linux or SUSE Linux EC2 instance:

ssh -i path/to/AccessKey.pem

If Ubuntu EC2 instance:

ssh -i path/to/AccessKey.pem

If Fedora Linux EC2 instance:

ssh -i path/to/AccessKey.pem

If necessary, see this guide on how to fix the permission error when SSH into EC2 instance on AWS

That’s it. That’s as short as I can keep this post.

Additional References:

Here’s some additional reading material that I think may be helpful:

That’s it! Keep learning…

Advertise on Amazon? Download our Free Amazon PPC Management Guide

12 Responses to "How to SSH to EC2 Instance on AWS (for Beginners)"

  1. Avatar
    Adam   July 9, 2017 at 6:20 pm


    I have tried this multiple times and I receive a “port 22: Operation timed out”…

    I’ve followed various other threads but no luck. I have done the following:

    -Updated inbound rules ( SSH -TCP-22- (I did not add myIP and just kept it open)
    -Ensured VPC set up properly
    -Ensured ACL ID inbound rules proper as well (a rule does show up with Rule# * that has Deny but I can’t delete it)

    Any help would be appreciated. Thanks!

  2. Avatar
    Faisal Athikkai   July 19, 2017 at 5:57 am

    Adam, please also make sure that the port 22 is opened.

  3. Avatar
    Anjana   July 19, 2017 at 1:20 pm

    Not related to ec2 instance, i am new to aws, i tried connecting to share data from my pc to aws using jdbc, while developing an app, i tried so many things to resolve it. I am getting perfect answer, everytime i will be getting different errors, really facing many difficulties, please help me if you know solution

  4. Avatar
    Christopher Mills   August 16, 2017 at 10:47 am

    ec2-user worked, but hadoop was suggested by aws… why would that be?

  5. Avatar
    Jayden   August 30, 2017 at 10:20 pm

    Thanks but I’m getting “Permission Denied” no matter what I try. So frustrating.

    • Avatar
      Jayden   August 30, 2017 at 10:22 pm

      Perhaps you could walk us through from start to connection. Eg. how to create the keys. What to do locally, etc. I still can’t resolve this permission denied error even after generating a new private key via the EC2 web interface.

  6. Avatar
    Satya   April 9, 2018 at 6:08 am

    Where actually the path is? i mean ssh -i /path/file.pem this directory isnt there for me, can you help me find where i can actually find my .pem file

  7. Avatar
    Eugene   May 2, 2018 at 11:12 pm

    how to put EC2 against access key?

  8. Avatar
    Emin   February 10, 2019 at 8:29 am

    Thank you!

  9. Avatar
    loki   May 1, 2019 at 4:38 pm

    I am a new learner, I connected to ec2 instance using ssh. what can we do after connecting to ec2, I mean like why exactly we need to connect to ec2 using even though we can login to aws account

    • Avatar
      Charlie   May 23, 2019 at 4:48 pm

      Loki – similar to all the things you can do when you login to cPanel for example, you can do by logging into the EC2. It’s same concept. For those that are comfortable with CLI, this is how they typically perform operations on the server.


Leave a Reply

Your email address will not be published.