Interview Prep/Linux/SSH, sudo and authentication

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.

All Linux questions Roadmap: Linux

More on SSH, sudo and authentication