Skip to Content

Bastion hosts

Bastion hosts for SSH access to instances in private subnets, the security group rules they need, and the newer alternatives.

What it is

A bastion host: users SSH from the corporate network to a bastion EC2 instance in the public subnet, whose security group allows port 22 only from the corporate CIDR; from there they SSH to instances in the private subnet, whose security group allows port 22 from the bastion's security group A bastion host: users SSH from the corporate network to a bastion EC2 instance in the public subnet, whose security group allows port 22 only from the corporate CIDR; from there they SSH to instances in the private subnet, whose security group allows port 22 from the bastion's security group

A single, locked-down entry point.
  • A bastion host is used to SSH into the private EC2 instances.
  • The bastion is in the public subnet, which is then connected to all other private subnets.
  • The bastion host security group must allow inbound from the internet on port 22 from a restricted CIDR, for example the public CIDR of the corporation.
  • The security group of the EC2 instances must allow the security group of the bastion host, or the private IP of the bastion host.

Not in the course slides

Today, AWS offers ways to reach private instances without a bastion: Session Manager (no open ports, no SSH keys) and the EC2 Instance Connect Endpoint (SSH to private IPs with no public IP or bastion). For "least operational overhead" or "no inbound ports", pick these. Bastions still appear in exam questions.

Exam tips

  • "SSH to instances in a private subnet" → bastion host in a public subnet (or Session Manager / EIC Endpoint).
  • Bastion SG → port 22 from the company's public CIDR only. Private instance SG → port 22 from the bastion's security group.

Common traps

  • "Open port 22 on the bastion to 0.0.0.0/0." Restrict it to known CIDRs.
  • "Put the bastion in a private subnet." It must be reachable, so it's in a public subnet.

Check yourself

The lab would need two instances and a key pair, so instead:

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt