ProxyJump is the OpenSSH option for reaching an internal server through a bastion host. With ssh -J user@bastion user@internal, the client connects to the bastion and then tunnels a second, end-to-end encrypted SSH session to the target inside that connection. Your private key never leaves your own machine.

How ProxyJump works: the bastion only forwards TCP

ssh -J asks the bastion for a TCP channel to port 22 on the target, the OpenSSH default, and negotiates the final SSH session through that channel. The bastion only moves encrypted bytes. It never sees your commands or your password, and it doesn't need any of your keys stored on its disk.

This has three practical consequences:

  • You authenticate twice, once on the bastion and once on the target, both times with your local key.
  • Your known_hosts checks both host fingerprints, so a compromised bastion can't silently impersonate the target.
  • The bastion must allow TCP forwarding. If its sshd_config sets AllowTcpForwarding no, the jump fails.

These are the most useful command-line forms:

# Single hop
ssh -J [email protected] [email protected]

# Bastion on a port other than 22
ssh -J [email protected]:2222 [email protected]

# Chained hops, comma-separated
ssh -J [email protected],[email protected] [email protected]

With chained hops, each bastion is reached through the previous one. The order of the list is the order of the path.

ProxyJump in ~/.ssh/config: bastion and internal server example

The ProxyJump directive in ~/.ssh/config does what -J does, without retyping it every time:

Host bastion
    HostName bastion.example.com
    User admin
    IdentityFile ~/.ssh/id_ed25519

Host db-internal
    HostName 10.0.2.15
    User deploy
    IdentityFile ~/.ssh/id_ed25519
    ProxyJump bastion

With this in place, ssh db-internal is all you need. The bastion resolves the HostName value, not your machine, so DNS names that only exist on the internal network work fine.

sftp and scp read the same config file. That means sftp db-internal also goes through the bastion, and since OpenSSH 9.0 scp uses the SFTP protocol by default anyway. Every directive is documented in the official ssh_config manual page.

ProxyJump vs ProxyCommand vs agent forwarding: comparison table

ProxyCommand ssh -W %h:%p bastion is the older way to do what ProxyJump does. The -W flag connects the standard input and output of an ssh to the bastion with the target host and port. It's still useful when the hop isn't ssh, such as a proxy or some other command.

What is comparedProxyJump (-J)ProxyCommand with -WAgent forwarding (-A)
Where the private key is usedOnly on your machineOnly on your machineOn your machine, but the bastion can request signatures
What the bastion exposesEnd-to-end encrypted bytesEnd-to-end encrypted bytesAn agent socket usable while you're connected
SyntaxOne directive or flagFull command with %h and %pForwardAgent yes plus a second ssh from the bastion
Chained hopsComma-separated listNested commands, hard to readManual, session inside session

Agent forwarding (ssh -A or ForwardAgent yes) solves a different problem: using your keys from a shell that is already on the bastion. While you're connected, anyone with root on that bastion can use your agent socket to authenticate as you to other servers. ProxyJump removes that risk because the final session starts from your own machine.

If both ProxyJump and ProxyCommand apply to a host, whichever ssh reads first wins and the other is ignored.

4 mistakes when configuring ProxyJump in ~/.ssh/config

  1. Putting ProxyJump under Host *. The rule then applies to the bastion itself, so it tries to jump through itself. Add ProxyJump none to the bastion block or narrow the pattern.
  2. Enabling ForwardAgent "just in case". ProxyJump doesn't need it. Keep it off unless you have to use your keys from inside the bastion.
  3. Loose local permissions. OpenSSH expects ~/.ssh at 700 and private keys at 600. Otherwise it ignores the key, and the first hop falls back to a password.
  4. A bastion without TCP forwarding. With AllowTcpForwarding no, the bastion accepts your login but refuses the channel to the target. Check sshd_config on the bastion, not on the internal server.

ProxyJump, Mosh and mobile: what goes through a bastion

Mosh uses UDP, by default on ports 60000-61000, and does no port forwarding. It starts mosh-server over an initial SSH connection, but all traffic after that travels as direct UDP between client and server. ProxyJump only carries TCP inside SSH, so it can't deliver that UDP to an internal server.

If you want Mosh and tmux on a machine with no public IP and no open ports, a bastion isn't enough. A private mesh network without open ports such as Prialo, or Tailscale, gives the phone a direct route to the server. Mosh can then keep the session alive when you switch from wifi to mobile data.

On a phone, the same principle behind ProxyJump applies: keys don't belong on intermediate hosts. In termi1, an SSH terminal for your phone, keys are generated on the device itself and stored in the system's secure storage. The private key never leaves the phone.

A few other details help with this workflow:

  • termi1's own keyboard has Esc, Ctrl and Tab, which you need when editing ~/.ssh/config on a server.
  • The AI turns a sentence such as "connect to db-internal through the bastion" into a command typed at the prompt without pressing Enter.
  • On connections tagged as production, Production Guard ensures nothing gets Enter automatically.

Frequently asked questions

What is the difference between ssh -J and ProxyJump?

ssh -J and the ProxyJump directive do exactly the same thing: they open a connection to the bastion and run the target's SSH session inside it. -J is for one-off use on the command line. ProxyJump in ~/.ssh/config makes it permanent for a host or a pattern.

Is ProxyJump more secure than agent forwarding?

ProxyJump is more secure than agent forwarding because the bastion only relays encrypted traffic and never gets access to your agent. With agent forwarding, whoever controls the bastion can use your agent to sign authentications while you're connected, even though they can't copy the private key.

Does sftp work through a bastion with ProxyJump?

Sftp works through a bastion because it reads the same ~/.ssh/config as ssh. If the host has ProxyJump set, sftp db-internal jumps through the bastion with no extra flags. The same applies to scp, which has used the SFTP protocol by default since OpenSSH 9.0.

Can Mosh be used through an SSH bastion?

Mosh can't usefully cross an SSH bastion. The initial SSH connection can jump, but UDP traffic on ports 60000-61000 must reach the server directly. For internal servers, a private mesh network such as Prialo or Tailscale provides that direct route without opening ports.