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
Difficulty level Easy
Root privileges No
Requirements AWS
Est. reading time 2m
[/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 https://console.aws.amazon.com/ec2/.
  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

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 ec2-54-211-235-9.compute-1.amazonaws.com:

ssh -i ~/.ssh/centos-aws-db-1.pem ec2-user@ec2-54-211-235-9.compute-1.amazonaws.com

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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig 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 VPNAlpine CentOS 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> for code samples. Still have questions? Post it on our forum