Skip to main content

SSH Jump Host: ProxyJump vs ProxyCommand vs Agent Forwarding

How to use an SSH jump host with ProxyJump, when ProxyCommand still matters, why agent forwarding is risky, and how to lock down the bastion itself.

To use an SSH jump host, connect with ssh -J user@bastion user@internal-host, or add ProxyJump bastion to the internal host's entry in ~/.ssh/config. Your client opens a TCP tunnel through the bastion and authenticates to the target end to end, so your private keys never leave your laptop. At DockLab we run our own servers behind bastions and keep agent forwarding off. This guide covers why, plus how to lock the jump host down.

Quick answer

  • One-off: ssh -J [email protected] [email protected]
  • Permanent: in ~/.ssh/config, define Host bastion, then add ProxyJump bastion to every internal host (or to a wildcard like Host 10.0.1.*).
  • Several hops: ssh -J hop1,hop2 target, or ProxyJump hop1,hop2.
  • Fallback for very old clients: ProxyCommand ssh -W %h:%p bastion.
  • Avoid ForwardAgent yes for this. ProxyJump never needs it, and it lets anyone with root on the bastion use your loaded keys.

How a jump host connection actually works

You can wire a bastion up in three ways, and they differ in where your session gets decrypted and what the bastion can do with your credentials.

ProxyJump (-J) arrived in OpenSSH 7.3 as "simplified indirection through one or more SSH bastions". The ssh(1) man page describes it as making an SSH connection to the jump host "and then establishing a TCP forwarding to the ultimate destination from there." The bastion only relays encrypted bytes. Your local client checks the target's host key against your local known_hosts and authenticates to the target with keys that never leave your machine.

ProxyCommand is the older, general-purpose hook. SSH runs a command and talks to the server over that command's stdin and stdout. ProxyCommand ssh -W %h:%p bastion does the same job as ProxyJump, because -W forwards stdio to a host and port over the secure channel. ProxyCommand can also run things that aren't SSH at all, like an HTTP CONNECT proxy through nc.

Agent forwarding (-A) is a different pattern. You SSH into the bastion, then run ssh again from there, and the bastion borrows your local agent to authenticate the second hop. The second session is decrypted on the bastion, the bastion's own known_hosts checks the target, and your agent is reachable from a socket on a machine you don't fully control.

MethodNeeds on bastionWhere the target session is decryptedExposure if bastion is compromisedUse it when
ProxyJump / -JTCP forwarding allowedYour laptopAttacker sees traffic metadata, not keys or session contentsAlmost always
ProxyCommand ssh -W %h:%pTCP forwarding allowedYour laptopSame as ProxyJumpClient older than 7.3, or you need per-hop options ProxyJump can't express
ProxyCommand with nc or a proxyShell access and nc, or a separate proxyYour laptopDepends on the proxyGoing through an HTTP or SOCKS proxy, not an SSH bastion
Agent forwarding, two manual hopsShell access, AllowAgentForwarding yesThe bastionAttacker can authenticate as you while you are connectedRarely, and only with confirmation or destination constraints

Set up ProxyJump in ~/.ssh/config

The command-line form is good for a quick test:

ssh -J [email protected]:2222 [email protected]

You want the config form for daily use, because the man page warns that "configuration directives supplied on the command-line generally apply to the destination host and not any specified jump hosts." A -i or -o you pass on the command line won't reach the bastion. Give the bastion its own block.

  1. Define the bastion as its own host

    Host bastion
        HostName bastion.example.com
        User alice
        Port 2222
        IdentityFile ~/.ssh/id_ed25519
        IdentitiesOnly yes
        ForwardAgent no
        ProxyJump none
    

    ProxyJump none matters if a later wildcard block could also match the bastion. Without it, SSH can try to reach the bastion through itself.

  2. Point internal hosts at it

    Host app1
        HostName 10.0.1.10
        User deploy
    
    Host db1
        HostName 10.0.1.20
        User postgres
    
    Host app1 db1 10.0.1.*
        ProxyJump bastion
        IdentityFile ~/.ssh/id_ed25519
        IdentitiesOnly yes
    

    Per ssh_config(5), "for each configuration directive, the first specified value will be used." Put specific blocks above general ones, and put Host * defaults at the bottom.

  3. Test with verbose output

    ssh -v app1 true
    

    You should see two "Authenticated to" lines: one for the bastion and one for 10.0.1.10 (via the proxy). If only the first appears, the problem is between the bastion and the target, not on your side.

To chain hops, list them in order: ProxyJump hop1,hop2. Each hop uses its own Host block, so you can give each one a different user, port and key.

ProxyJump also works for file transfer and tunnels, because they all go through the same SSH client:

scp -J bastion ./release.tar.gz app1:/tmp/
sftp app1
rsync -av -e "ssh -J bastion" ./site/ app1:/var/www/site/
ssh -L 5432:localhost:5432 db1

When app1 has ProxyJump in your config, plain sftp app1 and rsync ... app1: pick it up automatically. Our SFTP vs SCP vs rsync guide covers when to pick which.

When ProxyCommand is still the right tool

The ssh_config(5) man page says ProxyJump and ProxyCommand compete: "whichever is specified first will prevent later instances of the other from taking effect." Pick one per host.

ProxyCommand is still worth it in three cases.

  1. A client older than OpenSSH 7.3. That's rare now. Ubuntu 24.04 ships 9.6p1 and Ubuntu 26.04 ships 10.2p1 (Launchpad), but you may still meet old appliances and long-lived CI images.
  2. Proxies that aren't SSH. If you have to go out through a corporate HTTP proxy, the man page's own example is ProxyCommand /usr/bin/nc -X connect -x 192.0.2.0:8080 %h %p. Note that this is the OpenBSD nc syntax. On Debian and Ubuntu, -X needs the netcat-openbsd package.
  3. Wrapping the hop in something else, such as a cloud CLI that opens the tunnel, or a script that wakes a host first. Any command that reads stdin and writes stdout works.

The equivalent of ProxyJump looks like this:

Host app1
    HostName 10.0.1.10
    ProxyCommand ssh -W %h:%p bastion

%h and %p expand to the target host and port. Avoid the old ProxyCommand ssh bastion nc %h %p form. It needs a shell and nc on the bastion, so the bastion can't be a forwarding-only box.

Why agent forwarding is the risky option

The ssh(1) man page is unusually direct about this: "Agent forwarding should be enabled with caution." Anyone who can bypass file permissions on the remote host (root, or an attacker who got root) can use the forwarded agent socket. "An attacker cannot obtain key material from the agent, however they can perform operations on the keys that enable them to authenticate using the identities loaded into the agent." The same page then says: "A safer alternative may be to use a jump host (see -J)."

In practice, while your session to a shared bastion is open, a compromised bastion can log in to every server that trusts your key, including servers that have nothing to do with that bastion. Your key never gets copied, but it doesn't need to be.

People usually enable -A to run git pull from a private repository on a server. Better options:

  • A read-only deploy key on the server, scoped to that one repository.
  • Pulling on your laptop and pushing artifacts with rsync through ProxyJump.

If you really need forwarding, limit what it can do. ssh-add -c makes the agent ask for confirmation before every use of a key. ssh-add -h (OpenSSH 8.9 or later on both ends for forwarded use) restricts which hosts a key may be used on and through:

ssh-add -c -h bastion.example.com -h "bastion.example.com>10.0.1.10" ~/.ssh/id_ed25519

The ssh-add(1) man page notes the limit of this: an attacker with the remote socket can still use the key against hosts you allowed. Constraints shrink the blast radius but don't remove it.

Lock down the bastion itself

ProxyJump only needs the bastion to open a TCP connection on your behalf. It doesn't need a shell, a TTY or agent forwarding. Restrict a dedicated jump user in /etc/ssh/sshd_config.d/50-jump.conf, using keywords from sshd_config(5):

Match User jump
    AllowTcpForwarding local
    PermitOpen 10.0.1.10:22 10.0.1.20:22
    AllowAgentForwarding no
    X11Forwarding no
    PermitTTY no
    ForceCommand /usr/sbin/nologin

PermitOpen limits which host:port destinations the forward may reach, so a stolen jump key doesn't become a pivot onto your whole private network. ForceCommand stops interactive logins. A -J or -W connection doesn't request a shell, so it still works. Check and reload:

sudo sshd -t
sudo sshd -T -C user=jump,host=laptop,addr=203.0.113.5 | grep -Ei 'permitopen|allowtcpforwarding|permittty'
sudo systemctl reload ssh

Then point clients at the jump user (User jump in the bastion block). Admins who need a shell on the bastion get a separate account.

Errors you will actually see

  • channel 0: open failed: administratively prohibited: open failed: the bastion refused the forward. Check AllowTcpForwarding and PermitOpen for that user with sshd -T -C.
  • stdio forwarding failed followed by Connection closed by UNKNOWN port 65535: the bastion couldn't reach the target. Test from the bastion with nc -zv 10.0.1.10 22, or look at security groups.
  • Host key warnings for the internal IP: with ProxyJump, your laptop's known_hosts holds the target's key. If you recycle private IPs, use HostKeyAlias per host so 10.0.1.10 doesn't collide between environments.
  • Wrong key sent to the bastion: options on the command line don't apply to jump hosts. Move IdentityFile into the bastion's Host block.

Keep jump host config tidy with Include

Once you have more than one environment, put each one in its own file. Include loads other config files, and relative paths are "assumed to be in ~/.ssh" when used in a user config:

# ~/.ssh/config (keep Include at the very top)
Include config.d/*.conf

Host *
    ServerAliveInterval 30
    IdentitiesOnly yes
# ~/.ssh/config.d/prod.conf
Host prod-bastion
    HostName bastion.prod.example.com
    User jump
    ProxyJump none

Host prod-*
    ProxyJump prod-bastion

The trap is placement. The man page notes that Include "may appear inside a Match or Host block to perform conditional inclusion." If you add Include at the bottom of the file, below a Host line, it only applies when that host matches, and your included hosts quietly vanish. Keep it at the top. On Ubuntu, /etc/ssh/ssh_config already includes /etc/ssh/ssh_config.d/*.conf for system-wide defaults. For a fuller layout across ten-plus servers, see our SSH config file examples.

Choosing a client for bastion-heavy fleets

Plain OpenSSH handles all of the above, and for many people a terminal plus a good ~/.ssh/config is enough. GUI clients differ a lot in how they handle jump chains, per-hop keys and host key verification. Before you commit to one, test it against your real chain, not a single public VPS.

What we care about in DockLab: credentials and imported SSH keys sit in a local AES-256-GCM encrypted store, and SSH host key pinning flags it when a server's identity changes, which is the same check ProxyJump keeps on your laptop. We are not the right pick for everyone. MobaXterm has far more protocols and network tools if you are on Windows only, and Termius has mobile apps if you need to reach a bastion from your phone. Our comparison of DockLab, Termius, Warp and MobaXterm sets out the trade-offs, and pricing lists what each plan includes.

Frequently Asked Questions

Does ProxyJump need agent forwarding to work?

No. With ProxyJump, your local client authenticates to the bastion and then to the target directly through a TCP tunnel, using keys on your own machine. Agent forwarding is a separate feature, and you can leave ForwardAgent no everywhere when you use ProxyJump.

Can the jump host see my SSH session?

With ProxyJump or ProxyCommand ssh -W, the bastion relays encrypted traffic it can't decrypt. It can see that you connected, to which internal address and port, and how much data moved. With manual two-hop agent forwarding, the second session is decrypted on the bastion, so a compromised bastion could see it.

How do I use a jump host with scp or rsync?

scp takes -J directly, for example scp -J bastion file app1:/tmp/. For rsync, pass the SSH command with -e "ssh -J bastion". If the target already has ProxyJump in ~/.ssh/config, both tools pick it up without extra flags.

What is the difference between ProxyJump and ProxyCommand?

ProxyJump is a built-in shortcut for hopping through SSH bastions, added in OpenSSH 7.3. ProxyCommand runs any command you give it and uses its stdin and stdout as the connection, so it also covers HTTP proxies and custom wrappers. If both are set for a host, whichever appears first in the config wins.

Why does my ssh config Include not load any hosts?

The most likely cause is that the Include line sits below a Host or Match line, which makes it conditional on that block. Move it to the top of ~/.ssh/config. Then check the result with ssh -G hostname, which prints the configuration SSH will actually use.

Try it on your own servers

SSH, SFTP, a remote editor, a browser and AI in one desktop workspace.

DockLab runs on macOS, Windows and Linux. Start free and keep your whole server workflow in one window.

About the author

· Co-founder, Legacies

Horia builds DockLab and spends most days on remote servers, deploy pipelines and the tooling around them.