How to SSH into an EC2 Instance from Linux or Mac

SSH (Secure Shell) is a critical tool for managing your Amazon EC2 instances remotely. It allows you to execute commands on your cloud server as if you were physically present. In this guide, we'll walk through setting up and using SSH on Mac or Linux to access an Amazon Linux 2 EC2 instance.


1. Prerequisites

Before you begin, ensure you have:

✅ An Amazon EC2 instance running Amazon Linux 2.

✅ A .pem key file downloaded when you created your EC2 instance.

✅ A terminal (Mac Terminal or Linux command line).

✅ A public IPv4 address for your EC2 instance.

Port 22 open in your EC2 Security Group (this allows SSH access).


2. Verifying Security Group Settings

To check if your EC2 instance allows SSH:

  1. Open the AWS EC2 Console.
  2. Select your EC2 instance.
  3. Navigate to the Security tab.
  4. Ensure Inbound Rules allow SSH (Port 22) from 0.0.0.0/0 (or your specific IP for better security).

3. Preparing Your SSH Key File