DEV Community

Afzal Ansari
Afzal Ansari

Posted on • Updated on

How I debugged through AWS ec2 instance creation when SSH failed to work

Introduction:

Creating and connecting to an Amazon Web Services (AWS) EC2 instance is a fundamental skill for anyone working with cloud infrastructure. However, even experienced users can encounter challenges, such as failed SSH connections, when attempting to connect to newly created instances. In this blog post, we will explore the steps I took to debug an SSH failure while connecting to an EC2 instance, specifically when I created an instance without a key pair. By following these troubleshooting techniques, you can quickly identify and resolve similar issues.

When I started to create an ec2 instance, I came to this step where I needed to select key-pair(login) option. I chose without key-pair to create further as shown below.
Image description
By the time I got to start the instance and connect it through SSH after finishing all the steps, I grabbed the command and ran it in the terminal.
Image description
Next, I tried to setup as per the instruction given in the SSH connection without key-pair. I failed to do so.
Image description
After retrying several times, I realised that I am missing somewhere. Then I got to know I can't connect to the instance without key-pair.
Image description
I chose other option to connect the instance created.
Image description

Image description

Finally, I was able to connect through EC2 instance connect which opens you up a new tab to use the web based console.
Image description

If we want to connect ec2 instance using SSH and ignore the failures like me, we can follow the steps as such below

Step 1: Confirm SSH Configuration
The first step in troubleshooting an SSH connection issue is to ensure that the SSH configuration on the EC2 instance is correctly set up.

Image description

Step 2: Create and Associate a Key Pair
If you created the EC2 instance without a key pair, you won't be able to establish an SSH connection. In this case, you will need to create a new key pair and associate it with the instance:

Image description
We can also follow as such given following ways:
Generate a New Key Pair: In the EC2 Dashboard, navigate to the "Key Pairs" section and create a new key pair. Save the private key (.pem file) securely on your local machine.

Associate Key Pair with the Instance: Right-click on the instance in the EC2 Dashboard and select "Actions" > "Instance Settings" > "Attach/Replace IAM Role." Choose the newly created key pair, and AWS will associate it with the instance.

Conclusion:

Debugging SSH connection issues when creating an AWS EC2 instance can be a frustrating experience, but by following a systematic troubleshooting approach, you can identify and resolve the underlying problems. In this blog post, we explored the steps to confirm SSH configuration, create and associate a key pair, and establish an SSH connection. Remember to double-check security group rules, ensure the instance has a public IP, and verify the permissions and path of the private key. By mastering these techniques, you can effectively troubleshoot SSH connection failures and confidently manage your EC2 instances in AWS.

Top comments (0)