How to connect to AWS EC2 instance from local MAC machine

  1. Open an SSH client, MAC’s terminal for an instance.
  2. Locate your private key file. The key which was created when the EC2 instance was created. Example: Your-Server-Key-Pair.pem.
  3. Put that key at the following location at /Users/<YourMac’sUserName>/SSHKeys on your MAC.
  4. Run this command, to ensure your key is not publicly viewable.

    chmod 400 Your-Server-Key-Pair.pem
  5. Connect to your instance using its Public DNS (ec2-54-237-44-66.compute-1.amazonaws.com)

    Keeping the terminal at /Users/<YourMac’sUserName>/SSHKeys folder, run the following command:

    ssh -i “Staging-Server-Key-Pair.pem” ubuntu@<YourEC2’sPublicIPWithDashes>.compute-1.amazonaws.com

    Example : ec2-56-52-117-12

You will see the following response in the terminal after the client is connected with the Ubuntu server:

Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.11.0-1027-aws x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Mar 30 06:40:11 UTC 2022

  System load:  0.0                Processes:             130
  Usage of /:   71.6% of 129.02GB   Users logged in:       0
  Memory usage: 17%                IPv4 address for eth0: 152.32.20.122
  Swap usage:   0%

 * Ubuntu Pro delivers the most comprehensive open source security and
   compliance features.

   https://ubuntu.com/aws/pro

51 updates can be applied immediately.
To see these additional updates run: apt list --upgradable


*** System restart required ***
Last login: Tue Mar 29 09:01:19 2022 from 106.215.120.196
ubuntu@ip-172-31-20-112:~$ 

You MAC is connected now with your EC2 instance though the terminal.