skip to Main Content

I’m working on a project I have inherited and need to connect to an AWS EC2 instance. But I can not seem to connect to it. If I go into the EC2 Console, select the instance then connect. I would normally use SSH Client, but if I select this I get the following error:

No associated key pair
This instance is not associated with a key pair. Without a key pair, you can’t connect to the instance through SSH.

If I try Session Manager I get this error: We weren't able to connect to your instance

And If I try EC2 instance connect I get Failed to Connect to you instance error.

I only need to run some very basic maintenance tasks and keep this alive for another month or so. So do not want to jump in too deep!

If anyone can help me here would be most grateful.

2

Answers


  1. Here are docs describing how to connect to the instance: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html

    Referring to the two methods you mentioned:

    1. SSH connection to the instance requires:
    • run in a public network
    • with Internet Gateway set as a wildcard route in the routing table assigned to the subnet
    • with Elastic IP assigned to the instance
    • with EC2 key pair added to AWS and assigned to the instance
    1. Session manager requires:
    • AWS SSM agent running on the instance (it runs on AWS Linux by default, so you might want to change base AMI)
    • IAM policiy assigned to the instance role: AmazonSSMManagedInstanceCore
    Login or Signup to reply.
  2. Fallow these steps:
    Open an SSH client.
    Locate your private key file. The key used to launch this instance is key.pem
    Run this command, if necessary, to ensure your key is not publicly viewable.

    chmod 400 key.pem
    

    Connect to your instance using its Public DNS:

     ec2-1-3-2.2.ap-south-2.compute.amazonaws.com
    

    Example:

     ssh -i "key.pem" [email protected]
    

    Go to aws Security Groups edit inbound rules to allow ssh to defult port 22

    if you have a firewall configured for your server, you must also update the firewall rules to allow access on the new SSH port:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search