`Permission denied (publickey)` on a new EC2 instance.
IntermediateTroubleshootingVPC and Connectivity
Answer
Likely causes → Wrong key pair, wrong username, or wrong permissions on the key file.
Diagnose →
ssh -vvv -i key.pem ec2-user@host
chmod 400 key.pem
aws ec2 describe-instances --instance-ids i-0abc --query 'Reservations[].Instances[].KeyName'
Fix →
- Use correct user:
ec2-user,ubuntu,admin - Use the right key
- Use EC2 Instance Connect or SSM to inject a new key
Prevent → Document usernames per AMI.
More on VPC and Connectivity
`ssh: connect to host 3.250.1.1 port 22: Connection timed out`. Walk the checks.Beginner`ssh: connect to host ... port 22: Connection refused`. How is it different from a timeout?BeginnerPrivate instances cannot reach the internet; `curl: (28) Connection timed out after 10000 milliseconds`.IntermediateNAT gateway shows `ErrorPortAllocation` in CloudWatch and connections drop.IntermediateVPC peering is `active` but ping fails.IntermediateVPC Reachability Analyzer says `BLACKHOLE`. What does it mean?Advanced