SSH to EC2 Instance from Mac OS

2020/01/232 min read
bookmark this
Responsive image

Table of Contents

Introduction

This blog shows how to connect to an AWS Linux or Ubuntu EC2 instance from macOS.

Prerequisites

First, make sure you have an EC2 instance and the following two things:

  • The private key pair file available on your Mac (it should be something like *.pem)
  • The AWS EC2 instance's public IP address

Connect to EC2 from macOS

On your Mac, open the terminal window and navigate to the location that has the *.pem file.

Type the following command to set the correct permissions:

chmod 400 {your.pem}

It should look like this:

chmod 400 my-test.pem

The following is for connecting to Amazon Linux:

ssh ec2-user@{EC2 Public IP address} -i {YourPem.pem}

It should look like this:

ssh ec2-user@123.123.123.123 -i my-test.pem

The following is for connecting to Ubuntu:

ssh ubuntu@{EC2 Public IP address} -i {YourPem.pem}

ssh ubuntu@123.123.123.123 -i my-test.pem

Conclusion

Connecting to an EC2 instance from macOS is straightforward. Set the correct permissions on your .pem file using chmod 400, then use the ssh command with the appropriate username (ec2-user for Amazon Linux or ubuntu for Ubuntu) along with the instance's public IP address.