Connect To Amazon AWS EC2 Instance From a CentOS / RHEL Using SSH Client

I have created/launched Amazon Machine Image (AMI) instance powered by a CentOS/RHEL/Red Hat Enterprise Linux. How can I connect to my instance using OpenSSH Linux/Unix/OSX ssh client?

[donotprint][/donotprint]You can use OpenSSH ssh client program for logging into a remote machine and for executing commands on a remote machine. The same client can be used to login into Amazon AWS EC2 instance powered by a CentOS Linux / Fedora / RHEL.

Create a Key Pair For a New EC2 Instance

  1. Login to your Amazon EC2 console at
  2. Select the region i.e. click US East (N. Virginia). (See fig.01)
  3. From the left navigation pane, click Key Pairs.
  4. Click Create Key Pair.
  5. Type “key name” (such as “centos-aws-db-1”) in the new Key pair name box, and then click Create. (See fig.02)

    Fig.01: AWS Create SSH Key Pair (click to enlarge)
  6. Download the private key file, which is named centos-aws-db-1.pem, and keep it in a safe place. You will need it to access any instances that you launch with this key pair.

Fig.02: Create AWS EC2 SSH Key Pair For Login

You need to use this key-pair for all your new instances. If you lose the key pair, you cannot connect to your Amazon EC2 instances.

Set private key permissions

Use the chmod command to make sure your private key file isn’t publicly viewable:

chmod 0400 ~/.ssh/centos-aws-db-1.pem

Connecting to Amazon EC2 Instance from a RHEL/CentOS Linux/UNIX/OSX Using a SSH Client

The syntax is as follows:

ssh -i key-file-name-here.pam ec2-user@public-dns-name

In this example, I’m connecting using the key ~/.ssh/centos-aws-db-1.pem file, ec2-user name and the instance’s DNS name is

ssh -i ~/.ssh/centos-aws-db-1.pem

Sample outputs:

Fig. 03: Successfully ssh into my box powered by RHEL 7

SSH user names for various Linux distros

  • For Amazon Linux, the default user name is ec2-user.
  • For CentOS/RHEL, the user name is often root or ec2-user.
  • For Ubuntu, the user name is ubuntu.
  • For SUSE Linux, the user name is root.
  • Also, check with your AMI provider for username.

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...