Connecting to Your EC2 Linux Instance Using SSH

Emer Kurbegovic
2 min readJan 5, 2024

--

Amazon Elastic Compute Cloud (EC2) provides scalable and flexible cloud computing capabilities, allowing users to run virtual servers in the cloud. When working with EC2 instances, a common and secure method for connecting to Linux instances is using the Secure Shell (SSH) protocol. This article will guide you through the steps of using SSH to connect to your EC2 Linux instance, ensuring a secure and efficient remote access experience.

Prerequisites:

  1. An active AWS account.
  2. An EC2 instance running a Linux-based operating system.

Step 1: Gather Necessary Information

Before connecting to your EC2 instance, you’ll need the following information:

  • Public IP address or DNS name of your EC2 instance.
  • The private key file (.pem) associated with the key pair used when launching the instance.

Step 2: Set Appropriate Permissions for the Private Key

Ensure that the private key file has the correct permissions. Use the following command in your terminal:

chmod 400 your-key-file.pem

Replace “your-key-file.pem” with the actual name of your private key file.

Step 3: Connect to EC2 Instance Using SSH

Open your terminal and use the following SSH command to connect to your EC2 instance:

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

Replace “your-key-file.pem” with the actual name of your private key file, and “your-instance-public-ip” with the public IP address or DNS name of your EC2 instance.

Example:

ssh -i my-key.pem ec2-user@54.123.444.555

Note: The default user for Amazon Linux instances is often “ec2-user,” but for other Linux distributions, you might need to use “ubuntu,” “centos,” or another appropriate username.

Step 4: Accept the SSH Key Fingerprint

Upon the first connection, SSH will prompt you to confirm the authenticity of the host by displaying the key fingerprint. Type “yes” and press Enter to continue.

Step 5: You’re In!

If everything is set up correctly, you should now be logged into your EC2 instance via SSH. You will see the command prompt, indicating a successful connection.

Final Thoughts

Using SSH to connect to your EC2 Linux instance provides a secure and convenient way to manage your virtual servers in the cloud. By following the steps outlined in this article, you can establish a secure connection and leverage the power of your EC2 instance for various tasks and configurations.

--

--