Security
Difficulty: Intermediate
3 min read

SSH Bastion: Securing Access to Your Servers

Learn why and how to use an SSH bastion to secure access to your production or cloud servers.

Back to tutorials
What is an SSH bastion?
An SSH bastion (or "jump host") is a single, hardened and monitored server that serves as the sole entry point for accessing other servers within a private network. Rather than exposing every server to the Internet, only the bastion is accessible from the outside.

Why Use a Bastion?

  • Reduced attack surface: Instead of N exposed servers, you only have one to secure and monitor.
  • Centralized auditing: All access goes through a single point, which greatly simplifies logging and auditing of connections.
  • Simplified access management: You can manage access rights to the private network from a single place.
  • No VPN needed: For simple SSH access, a bastion is often lighter and easier to maintain than a full VPN.

Diagram of an Architecture with a Bastion


Your workstation ---> Internet ---> [SSH Bastion] ---> Private network (Web servers, DBs, etc.)
(Key A)                 (Key A)      (Key B)

The user authenticates to the bastion (with Key A), then from the bastion authenticates to the final server (with Key B).

Configuration

Step 1: The bastion server

Choose a machine (a small VM is often enough) and install a minimal Linux distribution. Apply security best practices:

  • Regular updates.
  • Fail2ban to counter brute-force attacks.
  • UFW (or another firewall) to allow only the SSH port (22), and only from trusted IPs if possible.
  • A hardened /etc/ssh/sshd_config configuration (no root access, key-based authentication only, etc.).

Step 2: SSH client configuration (your machine)

The modern and recommended method is to use the ProxyJump directive in your ~/.ssh/config file. It is much simpler and more secure than older methods like agent forwarding.

Edit or create the ~/.ssh/config file:


# Connection to the bastion
Host bastion
    HostName bastion.your-domain.com
    User admin_bastion
    IdentityFile ~/.ssh/id_rsa_bastion

# Connection to private servers via the bastion
Host private-server-*
    HostName %h.lan # %h is replaced by what you type (e.g. private-server-1.lan)
    User admin_server
    IdentityFile ~/.ssh/id_rsa_private_server
    ProxyJump bastion

Step 3: Transparent connection

Thanks to this configuration, you can now connect directly to your private server. OpenSSH will handle the intermediate connection through the bastion transparently.

ssh private-server-1

That's it! You are connected to private-server-1 by going through bastion.

Simplicity and Security
The ProxyJump directive handles the connection end to end without exposing your final server's private key to the bastion, which is a major advantage over other methods.

Copying Files with scp

This configuration also works directly with scp:

scp my_file.txt private-server-1:~/
Agent Forwarding (-A)
Avoid using agent forwarding (ssh -A) through a bastion unless you have absolute trust in its security and its administrators. If the bastion is compromised, an attacker could use your agent's socket to connect to your private servers on your behalf. ProxyJump does not carry this risk.

Conclusion

Setting up an SSH bastion is one of the most effective measures for securing a network infrastructure. It is a fundamental step that considerably reduces risk. Thanks to OpenSSH's ProxyJump feature, using it has become transparent and more secure than ever.

Written by

Morgann Riu

Cybersecurity and Linux administration expert. I share my knowledge through free tutorials and training to help system administrators and developers secure their infrastructures.

Frequently asked questions

ProxyJump or agent forwarding (ssh -A), which one should I use to cross a bastion?
ProxyJump, without hesitation. With ssh -A, the bastion has access to your SSH agent socket: if it is compromised, an attacker can use it to reach your private servers under your identity, without ever stealing a key. ProxyJump builds the tunnel end to end and the final server private key never leaves your workstation. Only use agent forwarding through a bastion if you have absolute trust in its security and its administrators.
How do I copy a file to a server sitting behind the bastion?
There is nothing special to do: once the ProxyJump block is in ~/.ssh/config, scp uses it exactly like ssh does. The command scp my_file.txt private-server-1:~/ goes through the bastion transparently. That is one of the benefits of declaring the jump in ~/.ssh/config rather than in a one-off command: every tool built on OpenSSH inherits it.
Do I need one Host block per private server in ~/.ssh/config?
No, and that quickly becomes unmanageable on a fleet. Use a wildcard pattern such as Host private-server-* combined with HostName %h.lan: %h is replaced by what you actually typed, so ssh private-server-1 resolves to private-server-1.lan. A single block carrying User, IdentityFile and ProxyJump bastion then covers the whole fleet.
Does an SSH bastion replace a VPN?
For plain SSH access to machines on a private network, yes, and it is often the better trade-off: a bastion is lighter to deploy and maintain than a full VPN, and it centralizes connection auditing at a single point. It only covers what travels over SSH, though. As soon as you need to expose other protocols to the client machine, a VPN becomes relevant again.
What exactly should be hardened on the bastion machine itself?
Since it is the only machine exposed to the Internet, it concentrates all the risk. A small VM with a minimal Linux distribution is enough, but it must be kept up to date, protected by Fail2ban against brute-force attacks, and filtered by a firewall (UFW or equivalent) allowing only SSH port 22, ideally restricted to trusted IPs. The /etc/ssh/sshd_config file must be hardened as well: root login disabled and key-based authentication only.

Share this tutorial

Did you enjoy this article?

Comments

Checklist Sécurité Linux

30 points essentiels pour sécuriser un serveur Linux. Recevez aussi les nouveaux tutoriels par email.

Pas de spam. Désabonnement en 1 clic.