skip to Main Content

I am attempting to connect to an AWS EC2 ubuntu instance over SSH on a windows 11 PC. I have done the following:

  1. Followed the OpenSSH installation instructions here.

  2. Set up OpenSSH key management as described here.

  3. Imported the public generated key that was created in step 2 to my EC2 instance through the AWS console.

  4. 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


  1. High level steps are as follows (see the reference article below for screenshots):

    1. Verify that the instance is ready
    2. Verify the general prerequisites for connecting to your instance
    3. Install PuTTY on your local computer
    4. Convert your private .pem key to .ppk using PuTTYgen
    5. Connect to your Linux instance (using the user name from AWS)

    This article also provides some useful instructions:

    • Transfer files to your Linux instance using the PuTTY Secure Copy client
    • Transfer files to your Linux instance using WinSCP

    Reference Doc: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html

    Login or Signup to reply.
  2. 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:

    ssh -i .EC2_INSTANCE_2_KEY_PAIR.pem ec2-user@PUBLIC_IP_ADDRESS
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search