An SSH bastion is the only machine on a network that accepts connections from outside; every other server listens only on the internal network. With ProxyJump, the client passes through the bastion without leaving keys on it, the session stays encrypted end to end, and agent forwarding becomes unnecessary.
SSH bastion design: one door, one port and no private keys
Design rule: only the bastion exposes TCP port 22 to the Internet. Internal servers accept SSH solely from the bastion's address. The rest of the design follows from that:
- Minimal surface: the bastion runs no applications, databases or deployment tooling.
- Keys only: Ed25519 (OpenSSH 6.5 or later) or FIDO2
ed25519-sk(8.2 or later), with passwords disabled. - No private keys on the bastion: it relays TCP. It never stores or uses users' keys.
- Closed destinations: each user can only jump to the
host:portpairs declared on the server. - Strict permissions:
~/.sshat 700 andauthorized_keysat 600, on the bastion and on every target.
ProxyJump in ~/.ssh/config: SSH bastion setup with a real example
The ProxyJump directive in ssh_config tells the client to reach the target by hopping through another host. Here is a complete ~/.ssh/config for one bastion and two internal servers:
Host bastion
HostName bastion.example.com
User jump
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
ForwardAgent no
Host app1
HostName 10.0.1.20
User deploy
ProxyJump bastion
Host db1
HostName 10.0.1.30
User deploy
ProxyJump bastionWith this file, ssh app1 opens a connection to the bastion. Inside it, it opens a second, complete SSH connection to 10.0.1.20. Authentication against app1 uses the client's key, and the bastion only sees encrypted traffic.
Without a config file, the equivalent option is -J. sftp and scp accept it too:
ssh -J [email protected] [email protected]
sftp -J [email protected] [email protected]
scp -J [email protected] backup.tar.gz [email protected]:/tmp/Since OpenSSH 9.0, scp uses the SFTP protocol by default, so all three tools travel over the same kind of channel through the bastion. For several hops, ProxyJump takes a comma-separated list that is followed in order. The full reference is in the ssh_config manual page.
sshd_config for an SSH bastion: restrict jumps and block agent forwarding
The bastion only needs local TCP forwarding to specific targets. It needs no shell, no X11 and no agent. Here is a starting /etc/ssh/sshd_config:
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
AllowStreamLocalForwarding no
GatewayPorts no
LogLevel VERBOSE
Match User jump
AllowTcpForwarding local
PermitOpen 10.0.1.20:22 10.0.1.30:22
PermitTTY noWhat each part of the Match block does:
AllowTcpForwarding localallows exactly what ProxyJump uses, and only for the jump user.PermitOpenpins whichhost:portpairs can be reached. Any other destination is refused.PermitTTY noblocks interactive terminals.
Check the syntax with sshd -t before restarting the service, and keep a session open in case something breaks. Every option is documented in the sshd_config manual page.
A caveat on AllowAgentForwarding no: the manual warns it does not help if the user has shell access, because they can install their own forwarder. The real defence is client-side: ForwardAgent no and never ssh -A.
ProxyJump vs agent forwarding through an SSH bastion: comparison table
With agent forwarding (ssh -A), anyone with root on the bastion can use your agent socket to authenticate as you while you stay connected. ProxyJump removes that risk because the key is never used from the bastion:
| Criterion | ProxyJump (-J) | Agent forwarding (-A) |
|---|---|---|
| Where the private key is used | Only on the client | On the client, on request from bastion processes |
| What root on the bastion gets | Encrypted traffic and connection metadata | Authenticating as you for as long as your session lasts |
| Who sees the target session in plaintext | Only the client and the target | The bastion too, since it runs the second ssh |
| Shell needed on the bastion | No; local TCP forwarding is enough | Yes; the second hop is launched from there |
| Bastion sshd directives | AllowTcpForwarding local and PermitOpen | AllowAgentForwarding yes and shell access |
Session logging on an SSH bastion: what it can and cannot record
With ProxyJump, the bastion cannot log commands. The session with the target is encrypted end to end, and the bastion only relays bytes. The right split is:
- On the bastion, who and when. With
LogLevel VERBOSE, sshd records the fingerprint of the accepted key at each login, along with the user and source IP. - On each target, what was done. Enable
LogLevel VERBOSEon the targets too. If you need terminal recording, do it there, where the session is in plaintext. - Off both, the copy. Ship logs to a separate log server, because root on the bastion could wipe the local ones.
To review today's logins on a systemd distribution (the unit is ssh or sshd depending on the distribution):
journalctl -u ssh --since today | grep AcceptedWith one key per person and per device, the logged fingerprint also tells you which device was used to log in.
Using an SSH bastion from a phone: Mosh, tmux and keys that stay on the device
Mosh does not pass through a bastion. It starts mosh-server over an initial SSH connection, then talks UDP directly to the target, by default on ports 60000-61000, and does no port forwarding. You can make the initial SSH hop with mosh --ssh="ssh -J [email protected]" [email protected]. Even so, UDP still has to reach the internal server, which breaks the single-door design.
From a phone there are two consistent options:
- SSH with ProxyJump plus tmux on the target. Run
tmux new -A -s main: if the phone switches networks and the connection drops, you reattach to the same session. - A private mesh network. With Prialo private mesh network or Tailscale you reach machines without a public IP, and Mosh works directly there.
In termi1, the mobile SSH terminal, Ed25519 keys are generated on the phone and stored in the system's secure storage. The private key never leaves the device, which is exactly what a bastion without agent forwarding requires. Its own keyboard provides Ctrl for the tmux prefix. On connections tagged as production, Production Guard ensures nothing gets Enter automatically and holds back anything that deletes, stops or changes something before it reaches the prompt.
Frequently asked questions
What is an SSH bastion host?
An SSH bastion host is the only server on a network that accepts SSH connections from the Internet; all other servers accept SSH only from it. It concentrates access control and logging on a minimal machine with no application services and no users' private keys.
Is ProxyJump safer than SSH agent forwarding?
ProxyJump is safer than SSH agent forwarding because the private key is only used on the client and the session with the target is encrypted end to end. With agent forwarding, root on the bastion can use your agent to authenticate as you while you remain connected.
Can an SSH bastion log the commands I run?
An SSH bastion used with ProxyJump cannot log your commands, because it only relays an encrypted session between client and target. It does log who connects, when, from which IP and, with LogLevel VERBOSE, the key fingerprint. Commands must be logged on the target server.
Does Mosh work through an SSH bastion?
Mosh does not truly work through an SSH bastion. The initial SSH connection can hop, but Mosh then needs direct UDP to the target, by default on ports 60000-61000. The alternatives are SSH with tmux on the target or a private mesh network.