Connect AWS EC2 Ubuntu instance via SSH

Open an SSH client, MAC’s terminal for an instance.

Get the location of your private key file on your local machine. The private key file was created at the time of Ubuntu EC2 instance was created. Let’s say the name of the file is My-Server-Key-Pair.pem.

Create a new folder named MySSHKeys at the root of your local machine.

Copy the private key of EC2 Ubuntu instance in that folder.

Run this command (Ubuntu or Mac’s local machine ) at ~/MySSHKeys folder to make sure that your private key is not publicly accessible.

chmod 400 My-Server-Key-Pair.pem

Connect to your EC2 Ubuntu instance using its Public DNS (Example:

Run the following command to connect to EC2 Ubuntu instance via SSH:

ssh -i "My-Server-Key-Pair.pem"

Your terminal will be connected to your EC2 ubuntu instance now via SSH.