← Back to all fixes
AWS

Cannot SSH into EC2 instance

The Issue

`ssh -i mykey.pem ec2-user@<ip>` hangs or gives connection refused.

Root Cause

Security group does not allow port 22, wrong key pair, wrong username, or instance is in a private subnet with no route to internet.

How to Fix
  1. Check Security Group inbound rules — port 22 must allow your IP or 0.0.0.0/0
  2. Verify correct username for the AMI: `ec2-user` (Amazon Linux), `ubuntu` (Ubuntu), `admin` (Debian)
  3. Check key pair: must use the .pem file used when the instance was launched
  4. Verify instance has a public IP (or use a bastion host if in private subnet)
  5. Check instance status in Console — it must be in "running" state and pass status checks