Home > Net >  Terraform AWS How use Security Group's port another that 22 for SSH
Terraform AWS How use Security Group's port another that 22 for SSH

Time:09-27

I want using another SG's port for SSH, not 22, but i get error. For example:

resource "aws_security_group" "ws_sg" {
    name = "WS SG"
    vpc_id = "${aws_vpc.ws_net.id}"
    tags = {
      "Name" = "WS SG"
    }
}

resource "aws_security_group_rule" "inbound_ssh" {
    from_port = 28
    protocol = "TCP"
    security_group_id = aws_security_group.ws_sg.id
    to_port = 22
    type = "ingress"
    cidr_blocks = [ "0.0.0.0/0" ]
}

resource "aws_security_group_rule" "egress" {
    from_port = 0
    protocol = "all"
    security_group_id = aws_security_group.ws_sg.id
    to_port = 0
    type = "egress"
    cidr_blocks = [ "0.0.0.0/0" ]
}

How fix it?

P.S. Maybee, this happing because i have free account?

CodePudding user response:

You mixed up your ports. Instead of

   from_port = 28
   to_port = 22

it should be:

   from_port = 22
   to_port = 28

CodePudding user response:

I some hastened. Not working

I tried connect PuTTY to port 28 and i got: Network error: Connection refused

If i change SG's inbounds for SSH 22, then connect to port 22 without problem. But if i change 22-28, that's all guys )

CodePudding user response:

Understood. I wanted to forward the port so that SSH had a port other than the standard 22. And the Security Groups just open the port and that's it. Misled "from_port" "to_port".

In general, I decided simply. In the instance, I add, for example, "Port 28" to /ets/ssh/sshd_config and open it in the Security Groups. Thats all.

  • Related