Member-only story
Connecting to an Ubuntu EC2 Instance Using a .txt Key File: A Step-by-Step Guide
Amazon Web Services (AWS) provides secure access to your EC2 instances using SSH key pairs. Typically, the private key file comes in .pem format, but sometimes you might receive it as a .txt file. In this guide, we’ll walk you through the steps to connect to an Ubuntu EC2 instance using a .txt key file.
What is a Key Pair?
A key pair consists of a public and private key used for secure SSH connections to your EC2 instance:
- Public Key: Stored on the instance.
- Private Key: Held by you and used for authentication during connection.
AWS typically provides the private key as a .pem file, but if it's in .txt format, don’t worry—you can still use it by converting it to .pem.
Step-by-Step Guide
Step 1: Verify the .txt Key File
- Open the
.txtfile in a text editor (e.g., VS Code or Notepad). - Ensure the file contains a valid private key. It should begin and end with the following lines:
-----BEGIN RSA PRIVATE KEY-----
(key contents)
-----END RSA PRIVATE KEY-----Step 2: Rename the .txt File to `.pem
To use the .txt key file with SSH, it must have the .pem extension. Rename it by following these steps:





