Mike Barkas

Software Technologies

Mike Barkas

Mike Barkas

Software Technologies

Using SSH Agent Forwarding

March 1, 2025

SSH Agent Forwarding: A Hidden Security Risk

SSH agent forwarding is a feature in OpenSSH that makes it easier to use your local SSH keys on remote systems—without needing to copy your private keys around. It’s incredibly useful, especially when jumping through multiple servers. But that convenience comes with serious security trade-offs.

What Is SSH Agent Forwarding?

SSH agent forwarding allows authentication requests from a remote machine to be forwarded to your local ssh-agent. This way, you can access additional systems from a remote host without re-entering your credentials or placing your keys on every server you touch.

The Security Risk

If a remote machine is compromised, your forwarded agent becomes a liability. Attackers with access to that remote host can interact with your agent and authenticate as you on other systems—without ever needing your private key. Essentially, your identity can be used to pivot deeper into your infrastructure.

Real-World Threat: Lateral Movement

One of the most concerning attack vectors enabled by agent forwarding is lateral movement. An attacker who gains access to one server can use your forwarded agent to authenticate to others, increasing the blast radius of a breach significantly.

How to Reduce the Risk

To use SSH agent forwarding safely (or avoid it altogether), consider the following:

Avoid agent forwarding on untrusted or shared hosts.

Set ForwardAgent no as your default in your ~/.ssh/config, and override it only where explicitly necessary.

Use bastion hosts or ProxyJump to manage access instead of relying on agent forwarding.

Enable confirmation prompts for your ssh-agent using the -c flag, which requires user approval for each authentication attempt.

Use hardware-backed keys like YubiKeys or smartcards that prevent agent forwarding misuse, even if the host is compromised.

Final Thoughts

SSH agent forwarding can be useful, but it introduces real risks—especially in production environments or high-security networks.

Always weigh convenience against the potential for exposure. If you’re managing critical infrastructure, it’s safer to avoid agent forwarding and use more secure alternatives like bastion hosts or hardware-backed authentication.