How to SSH into EC2 Using Linux?

How to SSH into EC2 Using Linux?

In the realm of cloud computing, Amazon Elastic Compute Cloud (EC2) stands out as a powerful and flexible solution for hosting virtual servers. One essential skill for managing EC2 instances is connecting to them securely through SSH (Secure Shell) using a Linux terminal. In this guide, we'll walk you through the steps to successfully SSH into your EC2 instances, ensuring a seamless and secure connection.


Before we dive into the SSH connection process, make sure you have the following prerequisites in place:

  1. Amazon EC2 Instance: Launch an EC2 instance through the AWS Management Console.

  2. Key Pair: During the EC2 instance creation, choose or create an SSH key pair. Save the private key (.pem) securely on your local machine.

Step 1: Open Your Terminal

Open a terminal window on your local machine. If you're using Linux, this is your command center for interacting with your computer and remote servers.

Step 2: Navigate to the Directory Containing the Private Key

Use the cd command to navigate to the directory where your EC2 private key is stored. For example:

cd /path/to/your/key

Step 3: Change Key Permissions

Make sure your private key is secure by adjusting its permissions:

chmod 400 your-key.pem

Step 4: Connect to EC2 Using SSH

Now, you can connect to your EC2 instance using the following SSH command:

ssh -i your-key.pem ec2-user@your-ec2-public-ip

Replace your-key.pem with the name of your private key file and your-ec2-public-ip with your actual EC2 instance's public IP address.

Additional Tips and Examples:

Using a Different User:

If you are connecting to an EC2 instance that requires a different username, replace ec2-user with the appropriate username. For Amazon Linux, it's usually ec2-user, for Ubuntu, it's ubuntu, and for CentOS, it's often centos.

Using DNS:

Instead of the IP address, you can use the DNS (Domain Name System) associated with your EC2 instance:

ssh -i your-key.pem

Troubleshooting Connection Issues:

If you encounter issues connecting, check your security group settings in the AWS Console, ensure your EC2 instance is running, and verify your private key's permissions.

Mastering the art of SSH into EC2 instances using Linux is a fundamental skill for any AWS user. With these step-by-step instructions, you can confidently establish a secure connection and take full control of your virtual server.

Related Searches and Questions asked:

  • How to Open SSH Port in EC2?
  • How to Connect SSH in AWS Linux?
  • How to Connect to EC2 with SSH PuTTY?
  • How to Open SSH Port in EC2 for Secure Remote Access
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.