← Back to all fixes
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
Check Security Group inbound rules — port 22 must allow your IP or 0.0.0.0/0Verify correct username for the AMI: `ec2-user` (Amazon Linux), `ubuntu` (Ubuntu), `admin` (Debian)Check key pair: must use the .pem file used when the instance was launchedVerify instance has a public IP (or use a bastion host if in private subnet)Check instance status in Console — it must be in "running" state and pass status checks