Interview Prep/Linux/SSH, sudo and authentication

An SSH key with a passphrase works interactively, but scripts fail with `Enter passphrase for key` prompts or `Permission denied` in automation.

BeginnerTroubleshootingSSH, sudo and authentication
Answer

Likely causes → No ssh-agent available in the non-interactive context.

Diagnose →

echo $SSH_AUTH_SOCK
ssh-add -l

Fix → For automation, use a dedicated passphrase-less key restricted on the server (from=, command=), or a CI secret loaded into an agent at job start (eval $(ssh-agent) && ssh-add - <<< "$KEY").

Prevent → Separate human and machine keys.

All Linux questions Roadmap: Linux

More on SSH, sudo and authentication