Connect AWS EC2 SSH

User
Connect aws ssh
Assistant
To connect to an AWS EC2 instance via SSH, follow these steps (assuming you're on a local machine like Windows/Linux/macOS and you already have your `.pem` or SSH credentials ready):

### โœ… **Standard SSH Method (with PEM file)**
#### ๐Ÿงพ Requirements:
– EC2 instance is **running**
– Security Group allows **port 22 (SSH)** from your IP
– You have the **EC2 public IP or DNS**
– You have the **`.pem` key file** (e.g., `my-key.pem`)

### ๐Ÿ–ฅ๏ธ **Command to SSH into EC2:**

ssh -i /path/to/your-key.pem ubuntu@ec2-xx-xx-xx-xx.compute-1.amazonaws.com

Replace:
– `/path/to/your-key.pem` โ†’ with the full path to your PEM file
– `ubuntu` โ†’ with the correct EC2 username (see below)
– `ec2-xx-xx-xx-xx.compute-1.amazonaws.com` โ†’ with your EC2 Public DNS or IP

### ๐Ÿง‘โ€๐Ÿ’ป Common EC2 usernames by AMI:
| OS | Username |
|—-|———-|
| Ubuntu | `ubuntu` |
| Amazon Linux | `ec2-user` |
| CentOS | `centos` |
| RHEL | `ec2-user` |
| Debian | `admin` |

### ๐Ÿงฑ Example for your saved info:
If you're using the PEM file at `D:awsk.pem` (as mentioned before) and your host is:

ec2-16-170-254-93.eu-north-1.compute.amazonaws.com

Then run this in your terminal (Git Bash/WSL/Ubuntu/Windows Terminal):

ssh -i "D:awsk.pem" ubuntu@ec2-16-170-254-93.eu-north-1.compute.amazonaws.com

**Windows CMD or PowerShell:**
You may need to convert path:

ssh -i "D:/aws/k.pem" ubuntu@ec2-16-170-254-93.eu-north-1.compute.amazonaws.com

### ๐Ÿ”’ Permission Error?
Run:

chmod 400 /path/to/k.pem

If on Windows, ensure the file is not accessible by others.

Need help connecting from Windows with **PuTTY** or using **IAM user instead of PEM**? Let me know.

Leave a Comment

Your email address will not be published. Required fields are marked *