SSH authentication fails to work after having worked previously
I am using the free tier and have cycled through several flavors of linux. The is issue that my ssh login to the instances works fine for some short period and then suddenly stops working. My Security Groups are setup correctly to allow the traffic. I am logging in from the same location each time. It simply returns Permission denied (publickey). I have cycled through 4 instances, have to re-establish a new vm each time and it keeps happening.
Since you are getting Permission denied, you know your security groups are configured to allow the traffic. It would be helpful if you pasted the exact error you receive.
Make sure you are using the right default user name for your AMI https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connection-prereqs.html
In the EC2 console, you can look at the details of the instance and make sure you are using the correct Key pair name.
The error message you mention indicates that the (public) encryption key stored on the instance for the user that you're trying to log into the instance with doesn't match the (private) encryption key that you have on your laptop or local host.
I would suggest doing some forensics on the root volume of an instance which has stopped working: Take the volume and mount it on another instance which is working, then look at the private key to see if it is the right key; look at the time/date stamp; look at logs to see if there was some process or user that changed it.
Does anyone else have access to your private/public keypair? If so, generate a new keypair and delete the old one.
Relevant questions
Suddenly cannot SSH into established EC2 instances in US-East-1
asked 2 years agoSSH into EC2 stops accepting connections after about 8 minutes
asked 6 months agoWhat is the difference between EC2 Instance Connect and Session Manager SSH connections?
Accepted Answerasked 3 years agoSSH authentication fails to work after having worked previously
asked 3 months agoStopped instance restarted - unable to login
asked 22 days agoUnable to SSH to new instances unless its an AWS Ami
Accepted Answerasked 3 years agossh to all EC/2 instances hanging as of ~8:30AM Eastern Time
Accepted Answerasked 6 months agoRoot User for Linux
asked 7 months agoMemory and CPU allocation for EC2 on Free Tier.
asked 4 months agoUnable to SSH to the ubuntu managed node using instance-id
Accepted Answerasked 5 days ago