Private key // web./pub

Greetings all,
my first post here and I’ve gotten myself a little confused with terraform keys. I “think” I’ve got a private key that i need to move into /root/.ssh/web.pub but the videos don’t show how to do this and I can’t find it on forums or in the manual.

So I can set up EC2 instances in terraform without issue including starting nginx.

I can SSH into my EC2 Ubuntu instance using remote linux VM after i generated AWS private keys. But this only works if i specific the my key which i have to be in the directory of.

sudo ssh -i ns.pem [email protected]*

when i add the below to my terraform file it fails, because i have no web.pub file in my .ssh directory. So how do i convert my ns.pem into web.pub or do i need a different key? I’d assume its not as simple as copying the contents of my ns.pem into a file called web.pub?

key_name = aws_key_pair.web.id
vpc_security_group_ids = [aws_security_group.ssh-access.id]

resource “aws_key_pair” “web” {
public_key = file(“/root/.ssh/web.pub”)
}

resource “aws_security_group” “ssh-access” {
name = “ssh-access”
description = “Allow SSH”
ingress {
from_port = 22
to_port = 22
protocol = “tcp”
cidr_blocks = [“0.0.0.0/0”]
}
}

any advice is appreicated.
Thanks,
Neil

You can extract the public key from the .pem file using ssh-keygen:

ssh-keygen -f keypair.pem -y

Many thanks, thats sorted it!