Skip to content

fix: trust new ssh hosts on first connection#42

Merged
sandipndev merged 1 commit into
mainfrom
fix/trust-new-ssh-hosts
Apr 20, 2026
Merged

fix: trust new ssh hosts on first connection#42
sandipndev merged 1 commit into
mainfrom
fix/trust-new-ssh-hosts

Conversation

@sandipndev
Copy link
Copy Markdown
Owner

Problem

On a fresh GitHub Actions runner (classic or self-hosted), the runner user's ~/.ssh/known_hosts doesn't yet contain the host in git_uri, so git clone fails with:

Host key verification failed.
fatal: Could not read from remote repository.

…before the action can acquire the lock. Seen in the wild: https://github.com/sandipndev/build/actions/runs/24690001595.

Every consumer currently has to add an ssh-keyscan step before calling the action, which defeats the point of a drop-in locking primitive.

Fix

Export GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=accept-new" in both the main and post scripts. accept-new auto-accepts a new host key on first connection and pins it thereafter, so subsequent connections are verified normally. No URI parsing needed — works for github.com, GitLab, self-hosted, anything.

Requires OpenSSH ≥ 7.6 (2017) — universally available on modern runners.

Test plan

  • Re-run the failing build CI (https://github.com/sandipndev/build/pull/17) pointing at this branch/commit — the ssh-keyscan workaround in that PR can then be reverted.
  • Existing consumers upgrading don't need any config change.

🤖 Generated with Claude Code

On a fresh runner, the user's known_hosts doesn't contain the git host
yet, so `git clone` fails with "Host key verification failed" before
the action can claim the lock. Setting GIT_SSH_COMMAND with
StrictHostKeyChecking=accept-new tells ssh to auto-accept a new host
key (and pin it thereafter), which removes the need for callers to
pre-seed known_hosts. Works for any git_uri host — github.com,
gitlab, self-hosted — without URI parsing.

Symptom seen in https://github.com/sandipndev/build/actions/runs/24690001595

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sandipndev sandipndev merged commit 68fd54d into main Apr 20, 2026
11 of 14 checks passed
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.

1 participant