Skip to content

fix: SSH agent not started before git clone/push in deploy_debian_repo workflow - #773

Closed
MisterTea with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-debian-repo-host-key-verification
Closed

fix: SSH agent not started before git clone/push in deploy_debian_repo workflow#773
MisterTea with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-debian-repo-host-key-verification

Conversation

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

The "Commit and push Debian repository" step failed with Host key verification failed / exit 128 because: (1) no ssh-agent was started, leaving SSH_AUTH_SOCK unset in the subsequent step's shell process; (2) ssh-keyscan exits 0 even on empty output, silently producing an unusable known_hosts.

Changes

  • ssh-agent lifecycle: start agent with eval "$(ssh-agent -s)" and export SSH_AUTH_SOCK/SSH_AGENT_PID to $GITHUB_ENV so the agent is reachable in downstream steps
  • Key loading: ssh-add - <<< "${DEBIAN_REPO_SSH_PRIVATE_KEY}" loads the key into the agent via stdin (never written to disk)
  • Verified known_hosts: capture ssh-keyscan -t ed25519,rsa,ecdsa github.com output into a variable and fail fast if empty before appending to known_hosts
  • Explicit core.sshCommand: set ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes so git uses only the agent key and keeps strict host-key verification
eval "$(ssh-agent -s)"
echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}" >> "${GITHUB_ENV}"
echo "SSH_AGENT_PID=${SSH_AGENT_PID}" >> "${GITHUB_ENV}"
ssh-add - <<< "${DEBIAN_REPO_SSH_PRIVATE_KEY}"

known_hosts_content="$(ssh-keyscan -t ed25519,rsa,ecdsa github.com 2>/dev/null)"
if [[ -z "${known_hosts_content}" ]]; then
  echo "ssh-keyscan returned no host keys for github.com" >&2
  exit 1
fi
printf '%s\n' "${known_hosts_content}" >> "${HOME}/.ssh/known_hosts"

git config --global core.sshCommand \
  "ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes"

… workflow

Root cause: the 'Configure SSH for Debian repository push' step wrote the
private key to a file but never started ssh-agent, so SSH_AUTH_SOCK was
unset in the next step. Additionally, ssh-keyscan exits 0 even when it
produces no output (e.g. port-22 temporarily unreachable), leaving an empty
known_hosts and triggering 'Host key verification failed.'

Fix:
- Start ssh-agent and export SSH_AUTH_SOCK / SSH_AGENT_PID to GITHUB_ENV
  so the agent is available to subsequent steps.
- Load the deploy key via `ssh-add -` (from stdin, never touches disk).
- Capture ssh-keyscan output and fail fast if it is empty, then write
  verified host keys to known_hosts with correct permissions.
- Set core.sshCommand with IdentitiesOnly=yes and StrictHostKeyChecking=yes
  so git explicitly uses only the agent key and enforces host verification.
Copilot AI changed the title [WIP] Fix host key verification failure in Debian repo workflow fix: SSH agent not started before git clone/push in deploy_debian_repo workflow Jul 11, 2026
Copilot AI requested a review from MisterTea July 11, 2026 03:27
@MisterTea MisterTea closed this Jul 21, 2026
@MisterTea
MisterTea deleted the copilot/fix-debian-repo-host-key-verification branch July 21, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants