I am attempting to connect to an AWS EC2 ubuntu instance over SSH on a windows 11 PC. I have done the following:
-
Followed the OpenSSH installation instructions here.
-
Set up OpenSSH key management as described here.
-
Imported the public generated key that was created in step 2 to my EC2 instance through the AWS console.
-
Run the SSH command
ssh -i “C:Users{user name}.ssh{private key name}” ubuntu@{EC2 domain name}
Following these steps gives me the following error: Permission denied (publickey).
Troubleshooting Steps Taken:
-
Changed the keys permissions so that only my user account has access as described here. (I’ve also tried changing the permissions so that instead of giving the user full control the user only gets read access).
-
Tried generating both RSA and ED25519 keys.
-
Tried changing permissions using chmod through WSL.
-
I found a good description here about what permissions should be, but I’m not sure how it would apply to a windows system.
I definitely think this is a key problem and not an OpenSSH problem because I am able to SSH into systems with just a username and password, but obviously that option is not viable for a AWS EC2 instance. I can use a key generated in the .ppk format with Putty and successfully connect, but I need to get OpenSSH working for what I am trying to do. Any help would be greatly appreciated.
Solution: For those who find this post, I figured out that my problem was I did not actually import the public key into my EC2 instance as I thought I did. Once I added my public key to the .ssh/authorized_keys folder on my server, I was able to connect.
2
Answers
High level steps are as follows (see the reference article below for screenshots):
This article also provides some useful instructions:
Reference Doc: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html
In my case I was using my own username instead of instance username. For example, for Amazon image we should use ec2-user. Working example: