SSH to EC2 Instance (Mac)
Prerequisites
- EC2 Instance: Running Linux instance
- Key Pair: Downloaded .pem file from EC2 launch
- Public IP: EC2 instance public IP address
- Security Group: SSH (port 22) access allowed
SSH Connection Steps
1. Prepare Key File
# Navigate to directory containing your .pem file
cd ~/Downloads
# Set correct permissions (required for security)
# Note that do not include space in file name
chmod 400 your-key-name.pem
2. Connect to EC2 Instance
# Basic SSH connection
ssh -i your-key-name.pem ec2-user@your-public-ip
# Are you sure you want to continue connecting -> yes
3. First Connection
- Welcome message: You’ll see the EC2 instance welcome screen
- You’re connected: You now have terminal access to your EC2 instance
- Disconnect: Use
exit or Ctrl+D to disconnect
Troubleshooting
Permission Denied
# Check key file permissions
ls -la your-key-name.pem
# Fix permissions if needed
chmod 400 your-key-name.pem
Connection Timeout
- Check Security Group: Ensure SSH (port 22) is allowed
- Check Instance State: Verify instance is running
- Check Public IP: Confirm you’re using the correct IP