Agent forwarding (`ssh -A`) works to the bastion, but `git pull` on the next host says `Permission denied (publickey)`.
IntermediateTroubleshootingSSH, sudo and authentication
Answer
Likely causes → Forwarding is disabled on the target (AllowAgentForwarding no), you used sudo (which drops SSH_AUTH_SOCK), or forwarding wasn't requested on the second hop.
Diagnose →
echo $SSH_AUTH_SOCK; ssh-add -l # on the inner host
sudo -E env | grep SSH_AUTH_SOCK
Fix → Use ProxyJump so keys never leave your laptop, and connect to the final host directly: ssh -J bastion app01. For git on the server, use deploy keys instead.
Prevent → Prefer ProxyJump over -A; forwarded agents can be abused by root on intermediate hosts.
More on SSH, sudo and authentication
`ssh deploy@server01` fails with `deploy@server01: Permission denied (publickey).`BeginnerPermissions on `~/.ssh` are correct, but you still get `Permission denied (publickey)` and the server log says `Authentication refused: bad ownership or modes for directory /home/deploy`.IntermediateKey auth fails only on RHEL with SELinux enforcing; the server logs show nothing unusual about modes.IntermediateAfter upgrading the client to a new OpenSSH, connections to an old appliance fail with `no matching host key type found. Their offer: ssh-rsa,ssh-dss`.IntermediateA user's RSA key stopped working against a new server: the server log says `userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms`.IntermediateSSH login takes 20–30 seconds before the password or key prompt appears.Intermediate