PREP WITH PROOF
Menu
NETWORKING & SECURITY / PRACTICAL GUIDE

SSH ProxyJump vs Agent Forwarding: Bastion Access Without Confusion

Compare SSH ProxyJump and agent forwarding, configure separate bastion and target identities, and diagnose failures with a local ssh -G lab covering 24 checks.

THE QUICK ANSWER

ProxyJump routes a local SSH client to a destination through a jump host. Agent forwarding makes a local authentication agent connection available remotely for authentication operations. A jump route does not inherently require agent forwarding. Configure bastion and target identities separately, inspect both effective configurations and diagnose the failing stage before changing access.

A bastion route does not automatically require agent forwarding

You can reach a public bastion, but the application server is accessible only from its private network. One approach is to log into the bastion and start another SSH client there. Another is to keep the SSH client on your workstation and reach the application server through the bastion. Those workflows can use the same machines while creating different authentication and trust arrangements.

Before adding -A to a command, decide which workflow you actually need. A route to a private endpoint and permission for a remote process to ask your local agent for authentication operations are separate requirements. A connection failure at one layer does not justify enabling a feature at the other.

This guide uses two invented aliases, pwp-bastion and pwp-app. Its complete lab inspects configuration locally with ssh -G. It does not connect to either server, create keys or start an agent. The resulting checks demonstrate client configuration selection; a real deployment still needs separate connectivity, host-identity and authentication verification.

Compare the location of the client and the authentication capability

OpenSSH describes ProxyJump, also available through -J, as an SSH connection to a jump host followed by TCP forwarding toward the target. The destination SSH client remains local. The -A option instead enables agent connection forwarding; -a disables it. OpenSSH cautions that sufficiently privileged remote users can use that forwarded connection for authentication operations even though they cannot extract the private key material through the agent.

For an interactive login to the private server, begin by evaluating a local-client ProxyJump configuration with agent forwarding disabled. A local agent may still help the local client authenticate. That is different from making the agent reachable through a forwarded socket on a remote machine.

If work really must run on the bastion and initiate its own SSH connections, review that separate requirement explicitly. An organization might provide constrained credentials or another approved mechanism for that workload. Do not assume that a successful jump-based login means every remote-origin operation also has the authentication capability it needs.

QuestionLocal client with ProxyJumpSSH started inside a bastion session
Where does the destination SSH client run?WorkstationBastion
How does it reach the destination?Forwarded TCP route via jump hostBastion network connection
Where is destination authentication initiated?Local clientRemote client on the bastion
Is a forwarded local agent required just for the route?NoNot inherently; depends on the chosen credentials
What should be reviewed separately?Jump and target identities, host keys, forwarding policyRemote workload credentials and any agent exposure

Source: OpenSSH ssh: -J, -A, -a and -G options ↗

Give the bastion and destination their own host blocks

The configuration below is a starting pattern for a workstation. Replace the invented hostnames, user names, port and key filenames with your approved environment. The application alias names the bastion alias in ProxyJump, so each connection has an explicit identity and destination. Do not copy the fixture’s placeholders into a production inventory unchanged.

Keep general defaults after specific host blocks. Most scalar settings use the first obtained value, and destination settings do not generally configure jump hosts. IdentityFile is additive. IdentitiesOnly narrows the offered configured identities; it does not mean “never use an agent.” These details are documented in ssh_config and checked where applicable by the lab.

The example keeps ForwardAgent no as a broad default. In an authorized real environment, ssh pwp-app would use the saved route. Do not run that login command merely to test this article’s invented names. The configuration inspection commands below are sufficient for the local exercise.

Host pwp-bastion
    HostName bastion.example.invalid
    User jumpuser
    Port 22
    IdentityFile ~/.ssh/pwp_bastion_ed25519

Host pwp-app
    HostName app.internal.invalid
    User appuser
    Port 2200
    ProxyJump pwp-bastion
    IdentityFile ~/.ssh/pwp_app_ed25519

Host *
    ForwardAgent no
    IdentitiesOnly yes
    CanonicalizeHostname no

Source: OpenSSH ssh_config: host selection, ProxyJump and identity settings ↗

Separate the two user identities from the two server identities

The user name and key offered to the bastion belong to the jump connection. The user name and key offered to the application server belong to the destination connection. Using one login name everywhere can hide which account is being rejected, especially when administrators assign separate access roles at each hop.

Server identity is a different question from user authentication. Verify the intended bastion and target host identities through your organization’s trusted mechanism. Do not remove host-key checking to make a routed connection work. A private-network location is not, by itself, proof that the answering server is the intended machine.

The existing host-key verification guide covers changed-key diagnosis in more detail. This article concentrates on the route and client placement. Keep the concerns separate in incident notes: “I cannot verify this host” needs different evidence from “this verified host rejected my user key.”

Run a local configuration lab without contacting a host

Save the complete Python script below as ssh_config_lab.py and run python ssh_config_lab.py with OpenSSH and Python available. The script creates only a temporary configuration file, uses absolute placeholder identity paths and removes the fixture afterward. The key files do not need to exist because no authentication is attempted.

The published script passed 24 checks across 10 ssh -G evaluations on OpenSSH_9.6p1 Ubuntu-3ubuntu13.18. It compares hostnames, users, ports, identity lists, forwarding settings and the selected jump alias. It also checks a target-port override, a route override, ordering of scalar defaults and accumulation of IdentityFile entries. The final ssh -V call reports the local version separately.

The -A case changes printed configuration only. It does not forward an agent or establish a session. Likewise, a passing port or hostname assertion does not show that the corresponding endpoint exists or that its server permits access. The assertions intentionally avoid making those claims.

Use only this trusted fixture for the exercise. ssh -G evaluates configuration; arbitrary configuration can contain executable Match conditions or other environment-sensitive behavior. The fixture includes no Include directives, Match exec commands, canonicalization or external helper commands. Do not treat configuration inspection as a sandbox for files obtained from an untrusted source.

from pathlib import Path
from tempfile import TemporaryDirectory
import subprocess

CONFIG = '''Host pwp-bastion
    HostName bastion.example.invalid
    User jumpuser
    Port 22
    IdentityFile /pwp-fixture/bastion_ed25519

Host pwp-app
    HostName app.internal.invalid
    User appuser
    Port 2200
    ProxyJump pwp-bastion
    IdentityFile /pwp-fixture/app_ed25519

Host *
    ForwardAgent no
    IdentitiesOnly yes
    CanonicalizeHostname no
'''
checks = 0
calls = 0

def check(value):
    global checks
    assert value
    checks += 1

with TemporaryDirectory(prefix='pwp-ssh-config-') as directory:
    cfg = Path(directory) / 'config'
    cfg.write_text(CONFIG)
    cfg.chmod(0o600)

    def dump(host, *options):
        global calls
        # Only trusted fixture configs: no Include, Match exec or helper commands.
        # -G prints effective configuration and exits; no login is attempted.
        command = ['ssh', '-G', '-F', str(cfg), *options, host]
        result = subprocess.run(command, text=True, capture_output=True,
                                check=True, timeout=5)
        calls += 1
        values = {}
        for line in result.stdout.splitlines():
            key, _, value = line.partition(' ')
            values.setdefault(key, []).append(value)
        return values

    target = dump('pwp-app')
    jump = dump('pwp-bastion')
    for values, host, user, port, key in [
        (target, 'app.internal.invalid', 'appuser', '2200',
         '/pwp-fixture/app_ed25519'),
        (jump, 'bastion.example.invalid', 'jumpuser', '22',
         '/pwp-fixture/bastion_ed25519'),
    ]:
        check(values['hostname'] == [host])
        check(values['user'] == [user])
        check(values['port'] == [port])
        check(values['identityfile'] == [key])
        check(values['forwardagent'] == ['no'])
        check(values['identitiesonly'] == ['yes'])
    check(target['proxyjump'] == ['pwp-bastion'])
    check(jump.get('proxyjump', ['none']) == ['none'])
    # These switches alter configuration output ONLY, not a live session.
    agent_on = dump('pwp-app', '-A')
    check(agent_on['forwardagent'] == ['yes'])
    check(agent_on['proxyjump'] == ['pwp-bastion'])
    agent_off = dump('pwp-app', '-a')
    check(agent_off['forwardagent'] == ['no'])
    changed_port = dump('pwp-app', '-p', '2222')
    check(changed_port['port'] == ['2222'])
    check(dump('pwp-bastion')['port'] == ['22'])
    route = dump('pwp-app', '-J', 'alternate.invalid')
    check(route['proxyjump'] == ['alternate.invalid'])
    check(route['forwardagent'] == ['no'])
    # First obtained scalar value wins: broad defaults placed first can win.
    cfg.write_text('Host *\n    ForwardAgent no\n' +
                   'Host pwp-app\n    ForwardAgent yes\n' + CONFIG)
    check(dump('pwp-app')['forwardagent'] == ['no'])
    cfg.write_text('Host pwp-app\n    ForwardAgent yes\n' + CONFIG)
    check(dump('pwp-app')['forwardagent'] == ['yes'])
    # IdentityFile is additive, unlike the scalar example above.
    cfg.write_text(CONFIG + '\nHost *\n    IdentityFile /pwp-fixture/extra_ed25519\n')
    check(dump('pwp-app')['identityfile'] == [
        '/pwp-fixture/app_ed25519', '/pwp-fixture/extra_ed25519'])

version = subprocess.run(['ssh', '-V'], text=True, capture_output=True,
                         check=True, timeout=5)
print(version.stderr.strip() or version.stdout.strip())
print(f'PASS: {checks} checks; {calls} ssh -G evaluations; no remote logins')

An agent inventory is not a forwarding requirement

An authentication agent can hold identities for local SSH authentication. Access is commonly located through environment configuration such as SSH_AUTH_SOCK, and the client can use agent-held identities without exporting that capability to a remote login. Consult the agent manual and your platform’s setup rather than starting additional agents until a connection happens to work.

If the local client offers unexpected keys, inspect the effective IdentityFile list and IdentitiesOnly setting first. The lab’s final case appends another IdentityFile and verifies that the list grows. This catches a common review mistake: a specific host block does not necessarily erase every identity added by matching general configuration.

When agent forwarding is deliberately enabled for a remote workload, keep the scope tied to that workload and the hosts you intend to trust with access. Agent restrictions and platform capabilities vary. This guide neither tests constrained-agent behavior nor establishes that an arbitrary forwarded-agent setup is safe.

Source: OpenSSH ssh-agent: authentication agent behavior ↗

Diagnose the failed layer before changing the configuration

Start with the exact command, alias and configuration file used by the failing workflow. Compare a configuration dump for pwp-app with one for pwp-bastion. Confirm the target port separately from the bastion port. In the lab, changing the destination port to 2222 does not change the independently inspected bastion configuration, which stays on port 22.

For a real, authorized connection, use verbose client output to identify the failing stage and handle the logs as operational data. A bastion authentication failure, inability to open the onward TCP channel, target host-key failure and target user-authentication failure are different observations. Record the last confirmed successful stage before changing keys or routes.

If the onward channel is refused or administratively prohibited, review the bastion’s forwarding policy and the permitted destination with its administrator. Server controls such as AllowTcpForwarding, PermitOpen and DisableForwarding can affect forwarding. Enabling client-side agent forwarding does not repair a blocked TCP route.

If the target is reached but rejects authentication, compare its effective user and identity settings with the target account’s policy. If the error involves resolving the private hostname, check name resolution from the part of the route that opens the onward connection. Keep firewall, DNS and authentication changes distinct so one successful retry does not conceal an unrelated configuration expansion.

Source: OpenSSH portable: official sshd_config manual source ↗

Inspect both effective configurations when maintaining the route

The commands below inspect a configuration file you control. Replace the file path with the real local filename; they do not ask SSH to log in. Reviewing the two aliases independently helps expose assumptions that were hidden in a longer one-line ssh command.

For ordinary scalar options, a broad value obtained earlier can remain in effect even when a later host block appears more specific. The lab deliberately demonstrates that order. Review included files and matching blocks in the real configuration rather than assuming the last visible line wins. Treat additive options, including IdentityFile, according to their own documented rules.

If a configuration also contains ProxyCommand, inspect its interaction with ProxyJump instead of assuming both routes combine. The client manual describes competition between those options. Prefer one understandable routing mechanism for the connection, then preserve the verified effective settings as a small regression fixture when refactoring the file.

# These inspect the selected local configuration and exit.
ssh -G -F ./workstation-ssh.conf pwp-app
ssh -G -F ./workstation-ssh.conf pwp-bastion

# Report the local OpenSSH client version.
ssh -V

Keep reachability and delegated capability explicit

A useful runbook states where the destination client runs, how its network connection reaches the target, which user identity each hop uses and whether any remote process receives access to an authentication agent. That description is more actionable than a blanket instruction to add -A whenever a bastion is involved.

Configuration inspection provides a repeatable first check. After it passes, verify the actual route, host identities, server policy and user authentication in an approved environment. Keep any remote workload’s additional credential needs as a separate decision. This gives you a clear path from a failed connection to a specific correction without silently broadening agent exposure.

KEEP THESE THREE THINGS

Your next steps

  1. Choose where the destination SSH client runs before choosing an authentication workflow.
  2. Keep jump-host and destination users, keys and host identities distinct.
  3. Use ssh -G on trusted configuration to inspect selected settings; it does not prove connectivity or authentication.
  4. A forwarding-policy failure calls for route and server-policy diagnosis, not automatic agent forwarding.

Sources & official resources

Linked resources checked on 2026-11-04. Technical behavior and provider guidance can change; check the documentation for the version you use.

About this guide and its recommendations

Published by Prep With Proof with AI-assisted drafting. Study routines and examples are editorial suggestions, not official exam instructions or claims of a learner's personal results. Cited provider facts are linked; ownership of recommended Prep With Proof products is disclosed. No competitor endorsement or guaranteed certification outcome is implied.

Suggest a correction →