Forwarding an SSH agent lets a remote session authenticate to another host with a key that stays on the workstation. It fits bastion and jump-host handoffs, but it also gives the trusted remote host a live signing path back to the local agent while the session is open.
The OpenSSH client enables agent forwarding with ForwardAgent yes in a matching Host block, or with -A for a single command. A forwarded session exposes an SSH_AUTH_SOCK path on the remote host; programs there can ask the local agent to sign authentication challenges, but they cannot read the private key file itself.
Keep forwarding host-specific and load only the identities needed for the onward connection. The server-side AllowAgentForwarding setting can further restrict which bastion accounts receive forwarded sockets, and the final proof is a remote ssh-add -l output that matches the local agent before an onward login succeeds.
$ ssh-add -l 256 SHA256:G9x8RpzHGWETUZiMicVJWorguVdQRuvL/1GwuBUBrl0 user@workstation (ED25519)
If the agent reports The agent has no identities., load the key that the internal host already trusts before enabling forwarding.
Related: How to add an SSH key to ssh-agent
$ mkdir -p ~/.ssh
$ chmod 700 ~/.ssh
$ vi ~/.ssh/config
Host bastion
HostName bastion.example.net
User ops
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
ForwardAgent yes
Do not place ForwardAgent yes in a broad Host * block because every matched remote host would receive a live agent socket while sessions remain open.
Tool: SSH Client Config Editor
$ chmod 600 ~/.ssh/config
OpenSSH may ignore client configuration files that are writable by other users.
$ ssh -G bastion | grep "^forwardagent " forwardagent yes
ssh -G prints the effective client settings after Host and Match processing.
Related: How to show SSH client configuration
$ sudo sshd -T -C "user=ops,host=bastion.example.net,addr=203.0.113.10" | grep "^allowagentforwarding " allowagentforwarding yes
Replace ops and the addr value with the account and client source address that should receive the forwarded agent.
$ sudoedit /etc/ssh/sshd_config
Keep an existing root session or console path open before changing /etc/ssh/sshd_config on a remote bastion.
AllowAgentForwarding no
Match User ops
AllowAgentForwarding yes
Place unconditional server directives before the first Match block. Later Match blocks apply only to sessions that meet their conditions.
$ sudo sshd -t
No output means the server configuration parsed successfully.
Related: How to test SSH server configuration
$ sudo systemctl reload ssh
Use sudo systemctl reload sshd on systems where the OpenSSH server unit is named sshd.
$ ssh bastion "ssh-add -l" 256 SHA256:G9x8RpzHGWETUZiMicVJWorguVdQRuvL/1GwuBUBrl0 user@workstation (ED25519)
The fingerprint should match the local ssh-add -l output because the remote host is querying the forwarded agent.
$ ssh bastion "ssh app.internal.example hostname" app.internal.example
A compromised bastion can request signatures from the forwarded agent while the session remains open, so close the session when the onward work is finished.