MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Terraform Error: Key is not in valid OpenSSH public key format

Code

==================================

provider "aws" {
  region     = "ap-south-1"
  access_key = ""
  secret_key = ""
}

resource "aws_key_pair" "terraform-demo" {
  key_name   = "terraform-demo"
  public_key = "file(/home/ec2-user/.ssh/authorized_keys)"
}
Code language: JavaScript (javascript)

Error

Error: Error import KeyPair: InvalidKey.Format: Key is not in valid OpenSSH public key format
        status code: 400, request id: fa4b1c85-4372-467a-a228-83a159a5d12b

  on check.tf line 7, in resource "aws_key_pair" "terraform-demo":
   7: resource "aws_key_pair" "terraform-demo" {Code language: JavaScript (javascript)

Solutions:

Try converting the key to an openssh format using the -f flag. 
ssh-keygen -i -f /home/ec2-user/.ssh/authorized_keys > mykey-openssh.pub # NOT WORKING
ssh-keygen -f terraform_ec2_key # NOT WORKING
ssh-keygen -i -f terraform_ec2_key.pub > terraform_ec2_key1.pub # NOT WORKING

WORK IS IN PROGRESSCode language: PHP (php)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Wetty – How to Install & Access Wetty (Web-based SSH) on AWS EC2 linux to access using browser

Wetty is a web-based terminal. It runs a small Node.js server that opens an SSH session and streams it to your browser over WebSockets, so you can…

Read More

EC2 Key Pairs vs AWS Credentials: Practical Fixes for SSH and Security Group Setup

New EC2 users often confuse AWS API credentials with EC2 SSH key pairs, then get blocked by security group rules. This guide separates each concept and shows repeatable CLI and console steps to get instance access working safely.

Read More

Secure Connectivity from Public to Private: Introducing EC2 Instance Connect Endpoint

No more Bastion hosts!! AWS announces EC2 Instance Connect Endpoint, a new feature that allows you to connect securely to your instances and other VPC resources from…

Read More

How to login linux server of AWS from windows using putty?

How to Generate PPK file from PEM using PuttyGen? AWS by default do not allow accessing a linux server using password so only key is allowed. But…

Read More

Example Terraform Code for AWS provider, resources aws_key_pair

This command would generate a public and private key $ ssh-keygen -f terraform_ec2_key This resources would import aws key pair Rajesh Kumar I’m Rajesh Kumar, a DevOps,…

Read More

Terraform Error: Failed to read ssh private key: no key found

Solutions private_key – The contents of an SSH key to use for the connection. These can be loaded from a file on disk using the file function….

Read More