Running a coding agent on a remote host over SSH? Check ForwardAgent for that host first
With ForwardAgent on, every process on the remote host that runs as your user can sign with the keys in your local agent, and a coding agent is one of those processes. We measured it against a local sshd on OpenSSH 10.4p1: no forwarding gives no socket, forwarding gives a working login to anything your keys reach, and a key added with ssh-add -c is refused. Four commands to check and fix it.
If you start a coding agent on a dev box, a cloud VM or a build server, the SSH config on your laptop decides what that agent can reach. A single line, ForwardAgent yes, often sitting in a Host * block copied from an old tutorial, gives every process on the remote host a live connection back to the keys in your local agent. The agent runs as your user on that host, so it is one of those processes.
The ssh_config manual says this about the option:
Users with the ability to bypass file permissions on the remote host (for the agent's Unix-domain socket) can access the local agent through the forwarded connection. An attacker cannot obtain key material from the agent, however they can perform operations on the keys that enable them to authenticate using the identities loaded into the agent.
The agent does not need to be hostile for this to matter. A prompt injection in a README, a malicious dependency script or a tool call you approved too quickly all run with the same access. The useful question is what a process on that host could do with the socket, and it is cheap to answer.
What we measured
OpenSSH 10.4p1 on macOS. We started a throwaway sshd on 127.0.0.1:2222 with its own host key, loaded one key into a fresh ssh-agent, and treated the local sshd as the remote host.
Without forwarding. The default for ForwardAgent is no, and ssh -G confirms what the effective config says:
$ ssh -G remote | grep -i '^forwardagent'
forwardagent no
$ ssh remote 'echo "SOCK=<$SSH_AUTH_SOCK>"; ssh-add -l'
SOCK=<>
Could not open a connection to your authentication agent.
With -o ForwardAgent=yes. The remote shell now has a socket, and it lists your key:
$ ssh -o ForwardAgent=yes remote 'echo "SOCK=<$SSH_AUTH_SOCK>"; ssh-add -l'
SOCK=</Users/.../s.LIo8UHJ8Yi.sshd.prefXJ0EpL>
256 SHA256:F5zk... (ED25519)
Listing is the harmless part. We then ran a second ssh from the remote side, told it to use only the forwarded socket (-o IdentityAgent="$SSH_AUTH_SOCK" -o IdentityFile=none), and it authenticated and ran a command: hop-ok. The private key never left the laptop. It did not need to. Replace the second host with github.com and the same step is a git push as you, to every repository your key can write to.
With a confirm-on-use key. After ssh-add -D and ssh-add -c <key>, the same hop from the remote host failed:
sign_and_send_pubkey: signing failed for ED25519 "..." from agent: agent refused operation
[email protected]: Permission denied (publickey,keyboard-interactive).
ssh-add -c makes the agent ask ssh-askpass before each use. In our run no askpass program was available, so the agent refused. On a desktop with one configured, you would get a prompt on your laptop for every signature, which is the point: a push you did not start is visible. We did not test the prompt itself.
Check and fix, in order
- See the effective setting for the host you use.
ssh -G <host> | grep -i '^forwardagent'. This reads everyHostandMatchblock and the include files, which a grep of~/.ssh/configdoes not. Also look forHost *withForwardAgent yes. - See what a session receives. On the remote host:
echo "$SSH_AUTH_SOCK"; ssh-add -l. A socket path and a list of keys means every process there running as your user, plus root, can use them for as long as the connection is open. - Turn it off for that host. Put
ForwardAgent noin its block, above anyHost *that enables it (the first value found wins). - Give the host its own, narrower credential. For one repository, use a GitHub deploy key. GitHub's documentation says deploy keys are "read-only by default" and write access is a checkbox ("Allow write access") when you add the key, and a deploy key cannot be reused across repositories, so each repository gets its own key pair. An agent that only has to read and run tests then holds a key that cannot push.
If you do need forwarding, for example to hop onward to a second host, two options reduce the exposure. ssh-add -c as above, or a hardware-backed ed25519-sk key that needs a touch for each signature. For reaching a host behind a bastion, ProxyJump (ssh -J bastion target) opens a TCP forward through the bastion, per the manual, and does not require forwarding your agent to it.
What this does not cover
- The measurement used a local sshd, not a cloud VM or a specific agent product. We could not run an agent CLI in the test this time, so the claim is about processes on the remote host in general. Check
env | grep SSH_AUTH_SOCKfrom inside the agent's own shell to see whether your setup passes it on. - Some posts online claim that a particular coding-agent app turns agent forwarding on by itself. We could not confirm that, so it is not part of this post. The check above tells you what your own config does, whichever app opens the connection.
For the broader pattern, where a limit holds only until a process can reach around it, see agent gates that are only a price and a Claude Code approval that stored a password. The agents mentioned here are in the library: Claude Code and Codex.
Get the next post when it ships
One email on Sunday with the new post and a short list of what shipped that week — new guides, tool updates, and a couple of links worth reading.