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?

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
[/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)

    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

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

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.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.