# How do I SSH through a jump host (bastion)?

Reach a server that only a bastion can see, with one command. ssh -J and ProxyJump explained with a tested example, scp through the jump, and common mistakes.

Source: https://valakes.com/learn/ssh-jump-host/

Last updated: 2026-11-25

Add -J user@bastion to the ssh command, or write ProxyJump bastion in the block of the server. ssh connects to the bastion first and opens the connection to the server through it.

Commands checked on Ubuntu 24.04.5 LTS (the ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b container image), 25 November 2026.

A jump host, also called a bastion, is a server you can reach from outside that in turn can reach servers you cannot. To get to the inner server, run `ssh -J deploy@bastion deploy@inner`. For a server you use often, write `ProxyJump bastion` in its block of `~/.ssh/config`, and `ssh inner` does the same.

## The setup used here

Two servers are involved. The bastion is on the network you are on. The target is only on a second network that the bastion also sits on, so you have no route to it. The file `~/.ssh/config` has a block for each, and the target names the bastion with `ProxyJump`:

```console
$ cat ~/.ssh/config
Host bastion
    HostName bastion.example.test
    User deploy

Host target
    HostName target.example.test
    User deploy
    ProxyJump bastion

Host *
    StrictHostKeyChecking accept-new
```

The first attempt goes straight to the target. It fails, and the failure is the point: from this machine the name does not even resolve.

```console
$ ssh deploy@target.example.test hostname
ssh: Could not resolve hostname target.example.test: Name or service not known
```

## Jump with -J

Name the bastion with `-J`. The user in front of the bastion's address is the user on the bastion, and the user in front of the target is the user on the target:

```console
$ ssh -J deploy@bastion.example.test deploy@target.example.test hostname
Warning: Permanently added 'bastion.example.test' (ED25519) to the list of known hosts.
Warning: Permanently added 'target.example.test' (ED25519) to the list of known hosts.
target
```

The command printed `target`, the host name of the inner server. ssh logged in to the bastion, asked it to open a connection to the target and talked to the target through it. Both host keys were new to this machine, so you see two warnings. Each server is checked against your own `known_hosts`, not the bastion's.

The connection from you to the target is encrypted from end to end. The bastion carries the bytes and cannot read them.

## Put it in the config file

Typing the jump every time gets old. The target's block in the file already has `ProxyJump bastion`, so the short form works:

```console
$ ssh target hostname
target
```

`ssh -G` shows the option that did it:

```console
$ ssh -G target | grep -E '^(hostname|user|proxyjump) '
user deploy
hostname target.example.test
proxyjump bastion
```

`ProxyJump bastion` uses the block named `bastion` for the first hop, so its address, user, port and key come from that block. Several jumps are separated by commas, as in `ProxyJump first,second`, and ssh uses them in that order.

## What ssh runs for you

Before OpenSSH 7.3 you wrote the same thing by hand with `ProxyCommand ssh -W %h:%p bastion`. The debug output shows that `ProxyJump` still does exactly this:

```console
$ ssh -v target true 2>&1 | grep -E 'Executing proxy command|Authenticated to target'
debug1: Executing proxy command: exec ssh -v -W '[target.example.test]:22' bastion
Authenticated to target.example.test (via proxy) using "publickey".
```

The `-W` option asks the first ssh to forward its standard input and output to the target's port 22. Nothing runs on the bastion except its normal sshd.

## Other tools follow the same config

`scp`, `sftp` and `rsync` read the file too, so the jump comes with the name:

```console
$ scp -q target:/etc/hostname /tmp/target-hostname
$ cat /tmp/target-hostname
target
```

If you have no config block, `scp -J deploy@bastion.example.test deploy@target.example.test:/etc/hostname .` works the same way.

## Mistakes people make

You forward your agent with `-A` to reach the inner server. You do not need to. With a jump, your keys never leave your machine, and a bastion that is compromised cannot use your agent. Agent forwarding gives the bastion that chance.

The bastion refuses to forward. If its sshd has `AllowTcpForwarding no`, the jump fails after the login to the bastion succeeded. Ask for forwarding on that account, or use a bastion that allows it.

The users differ. One user in front of the target is not enough when the bastion needs another one. Write both: `-J bastionuser@bastion targetuser@target`, or set `User` in each block.

The port belongs to the target only. `ssh -p 2222 -J bastion target` uses 2222 for the target. Give the bastion's port in the jump itself, as `-J deploy@bastion:2200`.

A jump set for every host. If `ProxyJump bastion` sits in `Host *`, ssh tries to reach the bastion through the bastion. Put the option in the blocks of the inner servers, or turn it off for one host with `ProxyJump none`.

A changed key on the bastion looks like a problem with the target, because the message comes while you connect to the target. The message names the host. If it is the bastion, [the host key fix](https://valakes.com/learn/host-key-changed/) applies to it first. The structure of the file itself is in [the config file article](https://valakes.com/learn/ssh-config-file/), and tunnels that carry other ports are in [port forwarding](https://valakes.com/learn/ssh-port-forwarding/).

## In Valakes

Valakes has the same idea. Set Jump host in the host editor to the host that forwards you. On the first connection it asks about the host key of every hop that is not trusted yet, labeled "Hop 1 of 2" and so on, and the shell opens on the last host.

[Read the docs: Hosts and production marking](https://docs.valakes.com/hosts-and-production/)

## References

- [ssh(1) on Ubuntu 24.04, the -J option](https://manpages.ubuntu.com/manpages/noble/man1/ssh.1.html)
- [ssh_config(5) on Ubuntu 24.04, ProxyJump and ProxyCommand](https://manpages.ubuntu.com/manpages/noble/man5/ssh_config.5.html)
- [sshd_config(5) at man7.org, AllowTcpForwarding](https://man7.org/linux/man-pages/man5/sshd_config.5.html)
- [OpenSSH manual pages](https://www.openssh.org/manual.html)

## Related articles

- [SSH config file (~/.ssh/config): examples that work](https://valakes.com/learn/ssh-config-file/): The file ~/.ssh/config stores the address, user, port and key of each server under a short name. After that, ssh app does the work of a long command.
- [How does SSH port forwarding work? Examples of -L, -R and -D](https://valakes.com/learn/ssh-port-forwarding/): ssh -L 9000:127.0.0.1:8080 app opens port 9000 on your machine and sends every connection to port 8080 on the server app. -R does the reverse, and -D turns the connection into a SOCKS proxy.
- [How do I fix "REMOTE HOST IDENTIFICATION HAS CHANGED" in SSH?](https://valakes.com/learn/host-key-changed/): The server now shows a different host key than the one saved in your known_hosts file. Check the new fingerprint with the server's owner, remove the old entry with ssh-keygen -R, and connect again.
