{"slug": "ec2-ssh-not-connecting-here-are-the-5-things-that-were-wrong-and-how-i-fixed", "title": "EC2 SSH Not Connecting? Here Are the 5 Things That Were Wrong (And How I Fixed Them)", "summary": "The article outlines five common reasons for SSH connection failures to an EC2 instance, including incorrect key file paths, wrong default usernames for different AMIs, unprotected private key files, missing inbound SSH rules in security groups, and accidentally using the private IP instead of the public IP. Each issue is paired with a specific fix, such as using absolute file paths, setting file permissions with `chmod 400`, and adding a security group rule for port 22 from the user's IP. The author emphasizes that these errors are typical for beginners and often omitted from tutorials, which only show the \"happy path.\"", "body_md": "I spent 3 hours staring at this error my first week with AWS:\n\"Permission denied (publickey)\"\nMy EC2 instance was running. My terminal was open. I'd followed a tutorial step by step. And still — nothing.\nHere are the 5 things that were wrong (and how I fixed each one):\nI had downloaded the key pair but was pointing to the wrong file path in my command. Sounds obvious. When you're new, it's not.\nFix: always use the full absolute path.\nssh -i ~/Downloads/my-key.pem ec2-user@\nDifferent AMIs use different default usernames. I kept typing \"ubuntu\" on an Amazon Linux instance.\nAmazon Linux → ec2-user\nUbuntu → ubuntu\nRHEL → ec2-user or root\nDebian → admin\nThis one catches almost everyone.\nSSH refuses to use a key file that other users can read.\nFix: chmod 400 my-key.pem\nRun that once and you'll never see \"WARNING: UNPROTECTED PRIVATE KEY FILE!\" again.\nI'd launched the instance but never added an inbound rule for SSH. The connection wasn't being refused — it was being silently dropped at the firewall level.\nFix: go to EC2 → Security Groups → Inbound Rules → add SSH (port 22) from your IP. Not 0.0.0.0/0 — just your IP. Keep it tight.\nI was copying the Private IP from the console instead of the Public IPv4 address. Private IPs only work if you're inside the same VPC.\nFix: use the Public IPv4 DNS or Public IP shown in the instance details.\nThe honest truth: none of these errors showed up in the tutorial I was following. Tutorials show the happy path. Real learning happens when something breaks and you have to figure out why.\nIf you've hit any of these — you're not alone. Every person working in cloud has been here.\nWhich one got you the longest? Drop it in the comments.", "url": "https://wpnews.pro/news/ec2-ssh-not-connecting-here-are-the-5-things-that-were-wrong-and-how-i-fixed", "canonical_source": "https://dev.to/pwnjoshi/ec2-ssh-not-connecting-here-are-the-5-things-that-were-wrong-and-how-i-fixed-them-4ccp", "published_at": "2026-05-23 16:10:47+00:00", "updated_at": "2026-05-23 16:32:11.792043+00:00", "lang": "en", "topics": ["cloud-computing", "cybersecurity", "developer-tools"], "entities": ["AWS", "EC2", "Amazon Linux", "Ubuntu", "RHEL", "Debian", "SSH", "VPC"], "alternates": {"html": "https://wpnews.pro/news/ec2-ssh-not-connecting-here-are-the-5-things-that-were-wrong-and-how-i-fixed", "markdown": "https://wpnews.pro/news/ec2-ssh-not-connecting-here-are-the-5-things-that-were-wrong-and-how-i-fixed.md", "text": "https://wpnews.pro/news/ec2-ssh-not-connecting-here-are-the-5-things-that-were-wrong-and-how-i-fixed.txt", "jsonld": "https://wpnews.pro/news/ec2-ssh-not-connecting-here-are-the-5-things-that-were-wrong-and-how-i-fixed.jsonld"}}