[英]AWS ec2 instance unable to ssh inside
I am trying to create a ec2 instance but I am facing a problem where I am totally unable to ssh inside even if my security group has port 22 opened.我正在尝试创建一个 ec2 实例,但我遇到了一个问题,即使我的安全组打开了端口 22,我也完全无法在 ssh 内部访问。
My terraform looks like this.我的 terraform 看起来像这样。
variable "path_to_public_key"{
default = "/<path-to-ssh>/.ssh/id_rsa.pub"
}
resource "aws_vpc" "demo-vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "Ec2-EFront-Demo-Vpc"
}
}
resource "aws_subnet" "efront-subnet" {
vpc_id = aws_vpc.demo-vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "eu-west-1a"
tags = {
Name = "EFront-Subnet"
}
}
resource "aws_network_interface" "efront-network-interface" {
subnet_id = aws_subnet.efront-subnet.id
private_ips = ["10.0.1.100"]
tags = {
Name = "Efront_primary_network_interface"
}
}
resource "aws_key_pair" "efront-ssh-key" {
key_name = "id_rsa"
public_key = "${file(var.path_to_public_key)}"
}
resource "aws_security_group" "allow-ssh-single" {
vpc_id = aws_vpc.demo-vpc.id
name = "allow-ssh-access"
description = "security group that allows ssh and all egress traffic"
egress {
from_port = 0
protocol = "-1"
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
protocol = "tcp"
to_port = 22
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "allow-ssh"
Environment = "Prod"
}
}
data "aws_ami" "ubuntu"{
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "Efront-DEMO" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3a.small"
subnet_id = aws_subnet.efront-subnet.id
associate_public_ip_address = true
security_groups = [aws_security_group.allow-ssh-single.id]
key_name = aws_key_pair.efront-ssh-key.key_name
tags = {
Name = "EFront-DEMO"
}
}
The terraform init and apply runs without any problem. terraform init 和 apply 运行没有任何问题。 the instance is healthy, but when I try to ssh inside the virtual machine.
该实例是健康的,但是当我尝试在虚拟机内部使用 ssh 时。 I get:
我得到:
ssh: connect to host <IP> port 22: Operation timed out
My security group allows access through port 22 and this is the only security group I have in place.我的安全组允许通过端口 22 进行访问,这是我拥有的唯一安全组。
I tried to change the chmod to 400 not he key swell, but nothing.我试图将 chmod 更改为 400 而不是他的键膨胀,但没有。
Any advice about why I am getting this error?关于我为什么会收到此错误的任何建议?
Check:查看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.