skip to content

Why is OpenSSH's ProxyJump (ssh -J) safer than agent forwarding for reaching hosts behind an SSH bastion?

level: middleimportance: should knowfreq 36%

answer

  1. where does the second ssh run
  2. the bastion relays ciphertext
  3. keys stay on the laptop
  4. host key checked end to end

basics

~20 s

With ProxyJump the bastion only relays an encrypted connection; the laptop runs the inner SSH session and authenticates to the target itself, so neither keys nor an agent socket reach the bastion. Agent forwarding lends that socket to the bastion.

solid answer

~50 s

The difference is where the second `ssh` runs. With `ssh -A` you log in to the bastion and run `ssh` there, so it needs your keys there, and forwarding provides them as a socket that root on the bastion can also use. With `ssh -J [email protected] [email protected]`, both sessions start on your laptop: the bastion is asked to open a TCP connection to the target, and a complete second SSH session runs through it, end to end. Authentication to the target is signed by the laptop's agent and the target's host key is checked against the laptop's `known_hosts`. The bastion sees only encrypted bytes and which host you connected to. ProxyJump replaces forwarding when the goal is getting through a hop; it does not help when a program on a remote host must authenticate onward itself.

code

bash · 7 lines
bash
# Agent forwarding: the inner ssh runs on the bastion and borrows a socket
ssh -A [email protected]
#   then, in the bastion's shell:
#   ssh [email protected]

# ProxyJump: both sessions start on the laptop; the bastion relays bytes
ssh -J [email protected] [email protected]

go deeper

for a junior

Recall that ssh -J reaches a host through a bastion without forwarding your agent, and that the bastion just passes encrypted traffic along.

for a middle

Explain where each inner ssh runs, who signs the target login, and whose known_hosts checks the target's host key in each design.

for a senior

Name the case ProxyJump cannot cover, a program on a remote host that needs credentials, and the scoped alternatives you would choose instead.

for a principal

Argue for making jump-host relaying the documented default for every team, and decide which remaining forwarding cases you would allow and how.

## Two ways through a bastion A **bastion** (jump host) is the one SSH server exposed to a network segment; internal hosts accept SSH only from it. Engineers have two common ways to reach an internal host through it, and they differ in where the inner `ssh` client runs. | | Agent forwarding (`ssh -A`) | ProxyJump (`ssh -J`) | |---|---|---| | Where the inner `ssh` runs | on the bastion | on the laptop | | What the bastion receives | a socket into the laptop's agent | an encrypted byte stream to relay | | Who signs the target login | the laptop agent, on the bastion's request | the laptop agent, on the laptop's request | | Who checks the target's host key | `ssh` on the bastion, with the bastion's files | `ssh` on the laptop, with the laptop's `known_hosts` | | What root on the bastion can do | sign logins as you while connected | drop or delay traffic, see who connects where | ## What the bastion holds in each case With **agent forwarding**, the bastion is a full participant. You log in, you get a shell, and you type `ssh db1` there. That inner client needs your credentials, so `sshd` on the bastion creates a socket that relays requests back to your laptop's agent. Root on the bastion can reach that socket and ask your agent to sign, which is how a compromised bastion becomes authenticated access to everything behind it. With **ProxyJump**, the bastion is a relay: - it authenticates *you* for the first hop, using a signature your laptop made locally; - it opens a TCP connection onward to the target on your behalf; - it copies bytes in both directions without being able to decrypt them; - it never holds an agent socket, a key or a session key for the inner connection. How the relay itself is carried, a TCP forwarding through the jump host, belongs with SSH port forwarding; what matters here is that it lends the bastion nothing. ## The inner session is end to end The connection to the target behaves as if the bastion were a cable: 1. The laptop connects and authenticates to the bastion. 2. The bastion opens a TCP connection to the target's SSH port. 3. The laptop runs a **complete, separate SSH handshake** with the target over that stream: key exchange, host key verification and user authentication. 4. The target's host key is checked against the laptop's `known_hosts`, so a bastion that tried to impersonate the target would trigger a host key warning. 5. User authentication to the target is signed by the laptop's agent, for the laptop's own connection. Because the agent is never exposed beyond the laptop, the attack "root on the bastion logs in to production as you" has nothing to work with. OpenSSH's documentation recommends this directly: the `ssh` manual's warning on `-A` ends with "a safer alternative may be to use a jump host". ## When ProxyJump does not replace forwarding ProxyJump solves *reaching* hosts through hops. It does not provide credentials to programs **running on** a remote host. If a deployment step on a server must itself open SSH connections, for example to fetch code or copy files to a third machine, ProxyJump from your laptop changes nothing for that program. The choices then are: - give that host its own narrowly scoped credential, so the task never needs yours; - run the task from the laptop instead, with ProxyJump reaching each host; - if forwarding is unavoidable, forward a separate agent holding only the needed key (`ForwardAgent` accepts a socket path), loaded with `ssh-add -h` destination constraints and a short `-t` lifetime. ## Practical notes - Several hops chain with commas: `ssh -J hop1.example.com,hop2.example.com target.internal.example`. - Options given on the command line apply to the destination, not the jump hosts; per-hop settings go in the client configuration file. - The bastion must allow TCP forwarding for ProxyJump to work; turning that off on a bastion forces users back toward riskier habits. - The bastion still learns metadata: who connected, when, and to which internal host. That is usually what a bastion is for.

  • Can root on the bastion read or tamper with a ProxyJump session?
    It can drop, delay or log the connection's metadata, but not read it: the inner session's keys are negotiated between laptop and target. Tampering or impersonating the target fails the host key check against the laptop's `known_hosts`, so `ssh` warns instead of connecting.
  • A script on a remote server must itself SSH to a third host. Does ProxyJump from your laptop help?
    No. ProxyJump only relays connections that start on your laptop; it lends nothing to processes on remote hosts. Give that server its own scoped credential, drive the step from the laptop, or, as a last resort, forward a dedicated agent holding one key with destination constraints and a short lifetime.

  • ProxyJump forwards your agent to the bastion behind the scenes.
  • With ProxyJump the bastion decrypts and re-encrypts the inner session.
  • ProxyJump requires your private key to be copied to the bastion.
  • ProxyJump also lets programs on the target use your keys onward.
  • Root on the bastion gains the same access with ProxyJump as with -A.