Cloud Notes: SSH Agent Forwarding via Jump Host
Simple step-by-step notes for using ssh-add with ProxyJump (-J) and agent forwarding (-A) to reach a private instance via a jump host.
Jan 2, 2025
SSH Agent Forwarding: Simple Steps (Case-first)
Case
You are at your laptop (home). A private EC2 instance sits in a VPC with no public IP. A jump host (bastion) does have a public IP. You need to SSH from your laptop → jump host → private instance without copying your private key to any server.
Quick goal
SSH from local to private instance in one command, using your local SSH agent for authentication.
Prerequisites
- An SSH key pair on your laptop (
~/.ssh/id_ed25519or similar). ssh-agentavailable (macOS/Linux) andssh-addinstalled.- Jump host reachable (public IP) and allowed in security groups.
- Private instance reachable from jump host (VPC routing/security groups).
Step-by-step (minimal)
- Start ssh-agent (if not already running):
# macOS / Linux (example)
eval "$(ssh-agent -s)"
- Add your private key to the agent:
ssh-add ~/.ssh/id_ed25519
# verify
ssh-add -l
- One-line connect (ProxyJump + agent forward):
ssh -i <pem.key> -A -J user@JUMP_PUBLIC_IP user@PRIVATE_IP
-Jtells SSH to hop through the jump host.-Aforwards your local agent so the private instance can authenticate using your key.
- Alternative: use an ssh config entry (recommended)
Host bastion
HostName JUMP_PUBLIC_IP
User ec2-user
ForwardAgent yes
Host private-1
HostName 10.0.2.15
User ec2-user
ProxyJump bastion
ForwardAgent yes
Then simply:
ssh private-1
- If it fails, quick checks
ssh-add -lshows your key(s).- Ensure jump host can reach the private IP (ping or
nc/telneton port 22 from jump). - Check security groups and route tables.
- Confirm
ForwardAgent yesor-Awas used.
Short security checklist
- Only forward agent (
-A) to trusted jump hosts. - Do not copy private keys to servers.
- Use passphrases and/or short-lived certs when possible.
- Limit jump host access (IP allowlist, MFA, logging).
If something goes wrong (quick fix)
Sometimes the SSH agent has stale or wrong keys loaded.
- Remove all keys from the agent:
ssh-add -D
- Add the correct key again:
ssh-add ~/.ssh/your-key.pem
- Retry the connection:
ssh -A -J user@JUMP_PUBLIC_IP user