A bastion host is a server deliberately exposed to the public internet that acts as the single entry point to a private network. Everything else in the network sits behind it, unreachable directly from outside. If you want to SSH into one of those private machines, you connect to the bastion first, then from the bastion to the target.
The term comes from military architecture. A bastion is a projecting part of a fortification designed to allow defenders to cover adjacent walls. The analogy is direct: one hardened point you defend carefully, rather than trying to defend the perimeter of an entire network.
Why use one?
If you run ten servers and expose port 22 on all of them to the internet, you have ten attack surfaces. Each one gets scanned, probed, and hit with automated login attempts constantly. You need to patch all ten, monitor all ten, and make sure each one is configured correctly.
Put all ten servers in a private network and expose only the bastion, and you have one surface to defend. The private servers have no public IP addresses and are unreachable from outside the network directly. The bastion can be audited more thoroughly, monitored more carefully, and locked down more aggressively than ten servers could be.
Bastions also centralize access logs. Every SSH connection to the private network goes through the same point, so you have one place to look when reviewing who accessed what and when. This matters for compliance (SOC 2, PCI-DSS, HIPAA all have access logging requirements) and for incident response when something goes wrong.
How it works in practice
Your private servers have no public IP address. The bastion does. When you SSH, you connect to the bastion, and the connection gets forwarded from there to the private server.
The modern way to do this is with ProxyJump in OpenSSH:
ssh -J user@bastion-ip user@private-server-ip
The -J flag tells SSH to first connect to bastion-ip, then use that connection as a tunnel to private-server-ip. From the private server's perspective, the connection is coming from the bastion, not from the internet.
You can make this permanent in ~/.ssh/config:
Host bastion
HostName 52.x.x.x
User ec2-user
IdentityFile ~/.ssh/my-key.pem
Host private-server
HostName 10.0.1.50
User ec2-user
ProxyJump bastion
IdentityFile ~/.ssh/my-key.pem
After that, ssh private-server handles the entire chain automatically. No need to SSH into the bastion manually first.
Agent forwarding vs key on the bastion
When you connect through a bastion, the bastion needs to be able to authenticate to the private server. There are two approaches.
Agent forwarding (ssh -A) allows your local SSH agent to be used by the bastion for the second hop. The bastion does not need a copy of your private key. Your client holds the key, and the bastion uses a forwarded connection to your agent.
ssh -A -J user@bastion user@private-server
The advantage is that your private key stays on your machine. The disadvantage is that agent forwarding is a security risk if the bastion is compromised. An attacker with access to a bastion running agent forwarding can use the forwarded agent to authenticate as you to any server that accepts your key.
Separate key pair: Put a dedicated private key on the bastion, used only to connect to private servers. Your key from the internet authenticates you to the bastion; the bastion has its own key that authenticates to private servers. If the bastion key is leaked, it only provides access from the bastion network, not from anywhere else.
For most teams, a dedicated bastion key is the safer approach. Agent forwarding is convenient but extends trust beyond where it needs to be.
What makes a good bastion configuration
Restrict port 22 to known IP ranges. If your team works from offices or uses a VPN, restrict inbound SSH on the bastion to those specific CIDR ranges. 0.0.0.0/0 (open to the world) means every IP on the internet can attempt to connect. Even with key auth, that exposure is unnecessary.
Disable password authentication. Key-only access means a leaked or guessed password cannot get an attacker in. Add PasswordAuthentication no to /etc/ssh/sshd_config on the bastion and reload sshd.
Keep the bastion minimal. Do not run application code, databases, or web servers on the bastion. Its job is to forward SSH connections. Every additional service is an additional attack surface.
Enable detailed logging. SSH authentication events go to /var/log/auth.log (Debian/Ubuntu) or /var/log/secure (RHEL/CentOS). Forward these logs to a centralized log store so they persist even if the bastion is compromised.
Patch regularly. The bastion faces the internet, so it is the first thing that gets hit when a new vulnerability is published. Keep the OS and SSH packages up to date.
Consider fail2ban. Even with key auth, automated scanners generate log noise. fail2ban watches SSH logs and temporarily blocks IPs after repeated failed attempts, which reduces log noise and adds a small layer of defense.
AWS-specific setup
On AWS, the standard bastion architecture looks like this:
- Bastion host in a public subnet with an Elastic IP
- Application servers in private subnets with no public IP
- Bastion security group: inbound port 22 from your IP range
- Private server security groups: inbound port 22 from the bastion's security group ID (not from the internet)
Using a security group ID as the source (rather than an IP range) means only instances that are members of the bastion's security group can reach port 22 on private servers. It also updates automatically if you replace the bastion.
AWS also offers Systems Manager Session Manager as an alternative. Session Manager lets you connect to EC2 instances through the AWS console using IAM permissions, without port 22 open at all and without a bastion. It is worth evaluating for new architectures. The tradeoffs: it requires the SSM agent installed on instances, it requires internet access (or a VPC endpoint) to reach the SSM service, and the tooling is different from standard SSH. For teams that already use IAM extensively, it is a clean solution. For teams that want to stick with standard SSH tools, a bastion is simpler to understand and operate.
Multi-hop and more complex topologies
Sometimes you need more than one hop. A database might be on a separate, more restricted subnet that even the main bastion cannot reach, with its own jump server.
You can chain ProxyJump hops:
ssh -J user@bastion1,user@bastion2 user@final-server
Or in the config file:
Host final-server
HostName 10.0.2.100
User deploy
ProxyJump bastion2
Host bastion2
HostName 10.0.1.10
User ec2-user
ProxyJump bastion1
Host bastion1
HostName 52.x.x.x
User ec2-user
IdentityFile ~/.ssh/main-key.pem
Each hop adds latency, so more than two hops becomes noticeable. For most architectures, one bastion is sufficient.
Using SSHDock with a bastion host
SSHDock has built-in jump host support. In the connection form, expand the "Jump Host" section, enter the bastion's public IP and your private key, and SSHDock handles the tunnel automatically. You connect to the private server directly from the browser, with the bastion as the intermediate hop.
For more detail on the network setup, see our bastion host setup guide, and for broader SSH hardening, see our guide to securing SSH.