Connect to the Amazon EC2 Linux Instance Using SSH Client

Connect Amazon EC2 Instance using SSH Client
This tutorial focuses on the steps to connect to the Amazon Elastic Compute Cloud Linux Instance using the SSH client.

 

Amazon Elastic Compute Cloud (EC2) offers scalable computing capacity for AWS Cloud users. Amazon EC2 eliminates the need to invest in hardware up front to deploy and develop applications faster. Users can use Amazon EC2 to launch, configure, and manage virtual servers, security networking, and storage. Amazon Elastic Compute Cloud also offers virtual computing environments, known as instances, for its users. Amazon EC2 enables users to scale down or up instances to handle changes in requirements or spikes in popularity, reducing the need to forecast traffic.

In order to set up an Amazon Elastic Compute Cloud Linux Instance, follow the steps mentioned in the “Set up an Amazon Elastic Compute Cloud Linux Instance“ tutorial. After we launch the EC2 Linux instance, users can connect to it and use it the way that they’d use a computer sitting in front of them. The following steps explain how to connect to the Linux instance using an SSH client.

 

Prerequisites

Before we connect to the AWS EC2 Linux instance, complete the following prerequisites.

  • First, check the status of the instance.

Ensure that the Linux instance has passed its status checks. After we have launched the instance, it will take a few minutes for the Linux instance to be ready so that they can connect to it. Users can view the status information of the instance in the Status check column on the Instances page.

 

  • Next, get the user name and public DNS name to connect to the instance.

In order to find the IP address or public DNS name of the instance and the user name that the user should use to connect to their instance, follow the below steps mentioned in the “Prerequisites for Connecting to the Instance” tutorial.

 

  • Install an SSH client on the local computer as required.

By default, the user system might need to have an SSH client installed. Users can verify this by typing ssh at the command line, and if the system doesn’t recognize the command, install an SSH client.

 

Default Username:
The default user name for the Amazon Machine Image (AMI) that the user used to launch their Linux instance is:

  • For the Amazon Linux Amazon Machine Image (AMI) and Amazon Linux 2, the default user name is ec2-user.
  • For a CentOS Amazon Machine Image (AMI), the default user name is centos.
  • For a Debian Amazon Machine Image (AMI), the default user name is admin.
  • For a Fedora Amazon Machine Image (AMI), the default user name is ec2-user or fedora.
  • For an RHEL Amazon Machine Image (AMI), the default user name is ec2-user or root.
  • For a SUSE Amazon Machine Image (AMI), the default user name is ec2-user or root.
  • For an Ubuntu Amazon Machine Image (AMI), the default user name is ubuntu.

 

>> Note: If the ec2-user and root user names do not work, check with the Amazon Machine Image (AMI) provider.

 

Connect to the Linux instance using an SSH client

In order to connect to the Linux Instance using an SSH client, follow the below steps:

  • Open a terminal window and use the ssh command to connect to the instance.
  • Specify the path and file name of the private key (.pem), the user name for the instance, and the public DNS name or IPv6 address for the user’s instance.
  • In order to connect to the instance, use one of the following commands:

 

(Public DNS) In order to connect using the instance’s public DNS name, enter the following command:

 

ssh -i /path/my-key-pair.pem my-instance-user-name@my-instance-public-dns-name

 

(IPv6) Alternatively, if the instance has an IPv6 address, enter the following command to connect using your instance’s IPv6 address:

 

ssh -i /path/my-key-pair.pem my-instance-user-name@my-instance-IPv6-address

 

  • After executing the above command, users should see a response similar to the one shown below:

 

The authenticity of host 'ec2-198-51-100-1.compute-1.amazonaws.com (198-51-100-1)' can't be established.
ECDSA key fingerprint is l4UB/neBad9tvkgJf1QZWxheQmR59WgrgzEimCG6kZY.
Are you sure you want to continue connecting (yes/no)?

 

  • Optionally, verify that the fingerprint in the security alert matches the fingerprint that the user previously obtained in the”get the instance fingerprint” section. If these fingerprints don’t match, we might be attempting a “man-in-the-middle” attack. If it is a match, continue to the next step.
  • Enter yes to continue.
  • Finally, users can see a response similar to the one shown below:Warning: Permanently added ‘ec2-198-51-100-1.compute-1.amazonaws.com’ (ECDSA) to the list of known hosts.

 

Get the Instance Fingerprint

In order to get the instance fingerprint, follow the below steps:

 

  • On the local system (not on the AWS Elastic Compute Cloud instance), execute the below get-console-output (AWS CLI) command in order to obtain the instance fingerprint:

 

aws ec2 get-console-output --instance-id instance_id --output text
  • Below is an example of what the output of the above get-console-output (AWS CLI) command should look like. The exact output can vary depending on the AMI version, operating system, and whether the user has generated an AWS key.

 

ec2: #############################################################
ec2: -----BEGIN SSH HOST KEY FINGERPRINTS-----
ec2: 1024 SHA256:7HItIgTONZ/b0CH9c5Dq1ijgqQ6kFn86uQhQ5E/F9pU 	
root@ip-10-0-2-182 (DSA)
ec2: 256 SHA256:l4UB/neBad9tvkgJf1QZWxheQmR59WgrgzEimCG6kZY 	
root@ip-10-0-2-182 (ECDSA)
ec2: 256 SHA256:kpEa+rw/Uq3zxaYZN8KT501iBtJOIdHG52dFi66EEfQ no comment 	
(ED25519)
ec2: 2048 SHA256:L8l6pepcA7iqW/jBecQjVZClUrKY+o2cHLI0iHerbVc 	
root@ip-10-0-2-182 (RSA)
ec2: -----END SSH HOST KEY FINGERPRINTS-----
ec2: #############################################################

 

Conclusion

This tutorial presents the steps to connect to the Amazon Elastic Compute Cloud Linux Instance using an SSH client. Hope this tutorial was helpful, and do reach out to us if you have any query or suggestions.

Share this post

Services to Explore

Stay up to date!

Stay up to date with the Web Hosting, Cloud and Server Management Industry News and Tutorials!

We will send you only the relevant emails, and we respect your privacy. Please review our privacy policy for more info.

Managed AWS Services

Focus on your business, and let us take care of your AWS Cloud Infrastructure!
From what you are reading, it seems you are interested in AWS Cloud and related technologies. If you have a moment to spare, please take a look at our Managed AWS Services, which might interest you even more!
Managed AWS Cloud

Value-Added Services

We have services that can help you run a successful business. With us, you don't have to worry about these areas because our experts will take care of it for you.

Introducing - WPHealers!

Complete WordPress Management, 24x7 Support & White Label Agency Plans!

WordPress migration service, security, white-label reseller services and lot more! Grab the introductory deals now!

WPHealers

ServerHealers uses cookies.