Trouble Logging into EC2 Instance with SSH Keys

March 4, 2026 5 answers
Asked by !KeepItLevel
I'm trying to access my AWS EC2 instance after a long break from using it, and I'm running into some login issues. I created an ED25519 key, set the correct permissions on both the public and private keys, and imported the public key into my new Ubuntu instance. After rebooting, I attempted to log in using `ssh -i keyfile ubuntu@IP` but I keep getting a 'permission denied (public key)' error. When I use the `-v` flag, the output indicates that it can't authenticate with my public key and there are no more methods to try. I also tried launching a new instance and letting AWS handle the key creation via the .pem file, but I encounter the same problem trying to log in with that as well. Any advice?

Answers

!warpB12
If youโ€™re getting back into AWS, I'd suggest looking into Session Manager (SSM). It allows you to connect to your instance without the need for SSH and handles everything through the AWS APIs. Just make sure your instance has the necessary IAM role permissions, like 'AmazonSSMManagedInstanceCore'. Itโ€™s an excellent tool that simplifies remote access!
Reply to this answer
low-relief
Double-check that youโ€™re using the right username! For Ubuntu AMIs, it should be `ubuntu`, while some other AMIs like Amazon Linux use `ec2-user`. It's a common mistake that catches people off guard, so just make sure you're logging in with the correct username!

Parsable: I remember getting stuck on that before too. It's a small detail that can be easy to overlook!

Reply to this answer
persp-2pt
Regarding the loss of direct login capabilities, I haven't seen anything change. In fact, AWS has improved connection methods! You can use Session Manager or EC2 Instance Connect for secure access. Highly recommend checking out the options available in the AWS documentation for these methods. They might help you out!
Reply to this answer
router table~
Donโ€™t treat your server like a pet! If you're worried about losing access, it's a sign to strengthen your setup. When launching instances, let AWS generate the SSH key for you, and simply use that key by name on new instances. I also use userdata scripts for setup and app installation, so it's all automated. This way, if I need a new instance, I can have it up and running quickly!
Reply to this answer
pewter.spoon
Itโ€™s best to lean towards SSM for terminal access nowadays. Plus, you can install an SSH helper to SSH straight from your local terminal! Itโ€™s straightforward to get started, so Iโ€™d look into that option if you havenโ€™t already!
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions