SSH Agent Protocol
The ssh agent protocol lets a local background program hold private keys and sign login data. It allows you to log in to servers without typing your passphrase each time. Teams often set up this agent so engineers can move between hosts with ease. Still, broad permissions or shared keys on remote hosts create big security risks. Anyone with root rights on a remote host can abuse a forwarded agent socket. How the ssh agent protocol works in practice When you start an SSH session, your client n
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
The ssh agent protocol lets a local background program hold private keys and sign login data. It allows you to log in to servers without typing your passphrase each time. Teams often set up this agent so engineers can move between hosts with ease. Still, broad permissions or shared keys on remote hosts create big security risks. Anyone with root rights on a remote host can abuse a forwarded agent socket.
How the ssh agent protocol works in practice
When you start an SSH session, your client needs to prove your identity. Instead of reading the private key file directly, the client talks to the agent. This talk happens over a local Unix domain socket on your machine. The ssh agent protocol defines the exact messages sent across this local socket.
First, the client asks the agent for a list of known public keys. The agent replies with the public keys it holds in memory right now. Next, the client sends those public keys to the remote SSH server. The server checks if any key is allowed to log in to that account.
If the server accepts a key, it sends a random challenge back to the client. The client forwards this challenge to the agent over the local socket. The agent uses the matching private key to sign the data in memory. It sends the signed response back to the client, which passes it to the server. The private key is masked in responses before reaching the agent process during this whole flow.
How OpenSSH certificates fit into agent workflows
Managing raw public keys across hundreds of servers takes a lot of manual work. OpenSSH 5.4 added support for user and host certificates to solve this problem. An OpenSSH certificate is much simpler than the X.509 format used for web traffic. The keygen tool signs a public key with a Certification Authority key.
This signed certificate holds the public key, an identity string, and valid user or host names. It also holds a set of options signed by the authority key. You can load both the private key and the certificate into your local agent. The ssh agent protocol then presents the certificate during login just like a standard key.
SSH Agent Forwarding Security + Model Context Protocol (MCP) Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native agent setups solve and what they miss
The native agent workflow solves the problem of typing passphrases over and over. It also keeps raw private key files off remote servers when you use agent forwarding. When you forward an agent, the remote server gets a socket that links back home. An engineer can hop from a bastion to an internal host using their local key.
Still, this native setup leaves a major security gap during active sessions. If an attacker gets root access on the bastion, they can read the forwarded socket. They do not receive unmasked the raw key, but they can ask your agent to sign challenges. They can impersonate you on any server your key can reach while you stay connected.
Even more important, the ssh agent protocol only handles the initial login check. Once the server lets the user in, the agent plays no further role. Native SSH keys and certificates decide who logs in, not what commands run next. They do not inspect individual shell commands or stop a user from reading sensitive data. They also do not mask private fields like emails, phone numbers, or card numbers in output. Teams need controls that work inside the session, not just at the login door.
Check SSH commands and file transfers on the host
OpenSSH keys and certificates decide who can log into a Linux host. They do not check what a one-shot command or file transfer does once the session starts. With hoop.dev, you run an open-source SSH server with guardrails on the host. It checks callers with OpenSSH certificates and works with ssh, sftp, scp, and rsync clients.
When a caller runs a one-shot command or moves a file, hoop.dev guardrails check the command or path before it runs. Then hoop.dev data masking masks matched sensitive patterns in downloads and output. Interactive shells carry no guardrails because keystrokes have no statement boundary. Teams can turn interactive shells off and allow only commands and file tasks. The audit trail logs who connected and what was allowed or refused, without storing keystrokes or file bytes. See the source on GitHub.
Frequently asked questions
Does the ssh agent protocol send private keys over the network?
No, the private key stays inside the memory of the local agent program. Only public keys and signed challenge responses travel across the network to the server.
Why is SSH agent forwarding risky on shared servers?
Agent forwarding places a live socket on the remote server. Any user with root access on that machine can use that socket to log in elsewhere as you.
Can the ssh agent protocol restrict which commands a user runs?
No, the protocol only manages keys and signs data during the login step. It has no control over the shell commands an engineer runs after logging in.
Related guides
In this post