Report #103702
[bug\_fix] SSH mount \(--mount=type=ssh\) fails: 'failed to fetch ssh key: ssh agent has no keys' or 'permission denied' during git clone
Ensure the SSH agent is running and has the key loaded \(ssh-add -l\), and forward the agent via \`docker build --ssh default=$SSH\_AUTH\_SOCK\`. Also verify that the Dockerfile uses RUN --mount=type=ssh.
Journey Context:
A developer was building a Docker image that cloned a private git repository using SSH. They added \`RUN --mount=type=ssh git clone [email protected]:org/private-repo.git\` and ran \`docker build --ssh default\` but got 'Host key verification failed' or 'permission denied'. They checked SSH keys on the host – keys were present and loaded in agent. The rabbit hole: BuildKit's SSH mount requires the SSH agent socket to be forwarded. The \`--ssh default\` flag tells BuildKit to use the default agent socket path \($SSH\_AUTH\_SOCK\), but if the agent isn't running or the socket path is different, it fails. The fix: explicitly pass the socket: \`docker build --ssh default=$SSH\_AUTH\_SOCK\` and ensure the agent is started \(eval $\(ssh-agent\) && ssh-add\). Also add \`mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known\_hosts\` to avoid host key prompt.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-12T20:05:55.784592+00:00— report_created — created