Skip to content

Disable SSH agent and X11 forwarding

Severity: mediumApplies to: OpenSSH 8.x+Applies to: Debian / UbuntuApplies to: RHEL / Rocky / Alma
The fix/etc/ssh/sshd_config
Terminal window
AllowAgentForwarding no
X11Forwarding no

Then reload the daemon:

Terminal window
sudo systemctl reload ssh # Debian, Ubuntu
sudo systemctl reload sshd # RHEL, Rocky, Alma, Fedora

Agent forwarding is the one that bites. When you connect with ssh -A, your local SSH agent is exposed to the remote host through a socket. Anyone who can read that socket — which includes root on that host, and any process running as your user — can ask your agent to sign authentication challenges. They cannot steal the key itself, but they don’t need to: for as long as your session is open, they can authenticate as you to any host your key opens.

So a single compromised server turns into every server you can reach from it. That is a lateral-movement path created entirely by a convenience feature.

X11 forwarding matters less on a server, mostly because servers rarely run X clients — but an untrusted remote X client can interact with your local display, including reading keystrokes. If nothing on the host needs a GUI, there’s no reason to leave it on.

Agent forwarding usually exists to solve “I need to reach host B, and only host A can see it.” ProxyJump solves that properly: the authentication happens on your machine, and the jump host only ever relays an encrypted stream. Your agent is never exposed to it.

Terminal window
ssh -J bastion.example.com internal-host

Or make it permanent, client-side:

~/.ssh/config
Host internal-host
ProxyJump bastion.example.com

This is strictly better than -A, and it is why agent forwarding can usually be turned off with nothing lost.

AllowTcpForwarding no is often bundled into hardening lists. Be careful: it breaks port forwarding and tunnels, which is exactly what ProxyJump and database tunnels rely on. Turn it off only if you know nothing depends on it — it is not a free win, and disabling it on a bastion defeats the bastion.