Connect AWS EC2 SSH
August 7, 2025 ยท AI Conversations
—
### โ
**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.