How to Log in to every Linux EC2 Amazon Machine Images: Amazon Linux, Ubuntu, Red Hat, SUSE Linux, Debian

How to Log in to every Linux EC2 Amazon Machine Images: Amazon Linux, Ubuntu, Red Hat, SUSE Linux, Debian

Overview

This article will show how to log in to every Linux EC2 Amazon Machine Image type. EC2 stands for Elastic Compute Cloud, and it is a virtual server in the cloud. Every virtual server has the option to run from a few different operating systems or Amazon Machine Images.

Materials

  • Computer

  • Terminal

  • An AWS Account

    • EC2 feature

Procedure

  • Log in to your AWS account

  • Select EC2 or type EC2 in the search bar to select it from there

  • To create an EC2, "Launch Instance"

  • When customizing an EC2, the "Quick Start" heading shows the following options for which operating system can be used to run an EC2:

    • Amazon Linux (AWS)

    • Ubuntu

    • Red Hat

    • SUSE Linux

    • Debian

Reminder

Every EC2 that is made must have a key pair login and the security group that enables port 22, to ssh or log into the instance successfully.

How to Create an Instance

  • Creating an instance for every Linux operating system is similar. This example will show how to create an Amazon Linux EC2.

  • Give the EC2 a name.

  • Each EC2 has different architecture and instance types. Read over each description and choose which options are best when customizing the instance. To avoid costs, select the free-tier options if applicable.

  • Create a Key pair name by clicking "Create new key pair". There will also be an option to use an existing key pair if one was created before. Old key pairs can be used to log in to new instances, but it is advised to have separate key pairs for each instance for best security practices.

  • Select "RSA" and .pem for "Key pair type" and "Private key file format" respectively. The option RSA makes two keys: a private key and a public key. When the key pair is finished creating, the private key can be downloaded while the public key is sent and stays in the newly created instance. Public keys encrypt text that is meant to be decoded to access some information or a system. Private keys are used to decrypt the text, such as the public key to access the information and in this case, to enter into the instance. The private and public keys file extension is ".pem" and should not be changed to anything else to corrupt the file.

  • After making the ".pem" key file, it can be found in the "Downloads" folder on your local computer. To access the EC2, the key pair file cannot be deleted!

  • Under Network Settings, create or use an existing security group that enables SSH traffic to SSH into the EC2. Choose "Create security group" if no security groups exist, otherwise choose "Select existing security group". Checkmark the box "Allow SSH traffic from", to enable the SSH feature to connect to the Amazon Linux image by using port 22.

  • Optional - Checkmarking the boxes "Allow HTTPS traffic from the internet" and "Allow HTTP traffic from the internet" allows you to connect to the instance from ports 443 and 80.

  • Afterward, launch the instance. Eventually, it will take a few seconds to start running.

  • Launch the terminal and change directories to the Downloads folder or the directory that contains the ".pem" file if it was moved to another directory.

How to Log into an Instance

  • The ".pem" key is always used to log into the instance. Below is the following format for how to log into an instance:
ssh -i "name_of_key_pair_file".pem "amazon_image"@"IPv4 Public IP"

Explaining the SSH Command to Log into the Instance

  • ssh - Is short for "secure shell". When using this command, you are entering the shell of another computer or server to control that machine.

  • -i - This parameter means to keep the program open and continuously running. In this case, the "-i" will connect to the server's shell for a long time.

  • "name_of_key_pair_file".pem - The ".pem" file that was made to connect to the instance.

  • "amazon_image" - Depending on the Amazon Machine Image, there is a specific keyword that is needed in the command to enter the server. Refer to "Amazon Image Names for each Amazon Machine Image" for which keyword is needed to SSH into the instance.

  • IPv4 Public IP - After the instance is created, go to "Instance ID" to retrieve the public address

Amazon Image Names for each Amazon Machine Image

Instead of writing "amazon_image" in the SSH command, write the following that matches the Amazon Machine Image:

Amazon Linux: ec2-user
Ubuntu: ubuntu
RHEL: ec2-user
SUSE: ec2-user
Debian: admin

Executing the SSH Command

To leave the instance, type "exit":

Log into an Ubuntu EC2

Log into a Red Hat EC2

Log into a SUSE Linux EC2

Log into a Debian EC2

Terminating Instances

When finishing using the instances, go back to the EC2 Instances page and select "Terminate Instance" under the "Instance state" menu

Deleting Key Pairs

  • When deleting the instances, it is optional and recommended to delete the key pairs if they will not be used to log in to new instances in the future. If the key pair is not being used, it should be deleted just in case no one else obtains them. To delete them, enter "Key Pairs"

  • Select the following key pairs that should be deleted

  • Navigate the "Actions" button" and select delete

  • Type "Delete" to confirm deletion