SSH agent forwarding is a footgun. Use ProxyJump instead.
You need to git pull on a server, or hop from a bastion to a box behind it, and your key only lives on your laptop. The advice you'll find is ssh -A — agent forwarding . It works, it feels clever, and it quietly hands every server you land on the ability to use your key as you. There's a better default that costs you nothing: ProxyJump . Here's why forwarding is riskier than it looks, and the…
When trying to access a server or jump from a bastion to a box behind it, and your SSH key is only available on your laptop, many people reach for the command `ssh -A`, which enables agent forwarding. While this approach may initially seem clever, it inadvertently grants every server you connect to the ability to utilize your key.
This poses a significant security risk, as compromised servers could misuse your key as if it were yours, potentially gaining access to any machine your key has permissions for during your session.
Fortunately, there is a more secure alternative: `ProxyJump`. This command achieves the same result as `ssh -A` but without exposing your SSH agent to the remote server. By using `ProxyJump`, you can hop through a bastion host to reach your destination while keeping your SSH key securely on your device. To set this up permanently, you can add the following lines to your `~/.ssh/config` file:
```
Host db-internal
HostName 10.0.0.5
ProxyJump bastion
```
Now, when you execute `ssh db-internal`, the connection will transparently route through the bastion host, maintaining the security of your key. This method provides the same convenience as `ssh -A` without the associated risks.
Another common scenario where `ssh -A` is often used is running `git pull` on a remote server. To address this securely, consider using deploy keys instead of your personal key. Deploy keys are specific to each repository, read-only, and can be revoked if necessary. Alternatively, you can clone repositories using HTTPS with a scoped token, which also keeps your personal key off the server entirely.
While agent forwarding might be justified in specific circumstances, such as when you fully trust the intermediary host and intend to use it only temporarily, it is generally overused and recommended to be avoided. If you must use it, take extra precautions by enabling `ssh-add -c` to confirm each use and setting a timeout with `ssh-add -t`. It is essential to avoid forwarding to shared, managed, or third-party servers, as these environments increase the risk of compromise.
On mobile devices, the risks associated with agent forwarding are even more significant. Keys should reside in the device's secure enclave to prevent unauthorized access. Mobile clients should offer saved ProxyJump configurations per host, ensuring the safe method is straightforward and easy to use. TermAI, for instance, provides this functionality by allowing saved ProxyJump hops and confirming the key usage through biometric authentication, effectively preventing the default use of `ssh -A` from being a security risk.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.