Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

SSH to GitHub asks to confirm the host, or hangs on that prompt

ErrorThe authenticity of host 'github.com (140.82.112.3)' can't be established.

Short answer

SSH has never seen github.com from this machine, so it asks you to trust the server key. Compare the fingerprint it prints with the ones GitHub publishes, then type yes. On a server, script or CI job, add GitHub's published host keys to known_hosts, or use StrictHostKeyChecking accept-new.

  • Applies to OpenSSH 9, Ubuntu 24.04, git, GitHub SSH
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run GitHub's own connection test. It shows the fingerprint and the prompt, and on success it greets you by username.

    ssh -T git@github.com
  2. 2Match what you see, then jump to its fix

    1. 1The prompt shows an ED25519 fingerprint for github.com and waits for yes or noFirst connection from this machine, so the host key is not in known_hosts yetFix
    2. 2git clone or git pull over SSH stops, fails, or hangs on a fresh server, deploy runner or Docker buildA script, container or CI job cannot answer the promptFix

What does the error look like?

  • The authenticity of host 'github.com (140.82.112.3)' can't be established.
  • ED25519 key fingerprint is SHA256:
  • Are you sure you want to continue connecting (yes/no)?

Cause 1 of 2

First connection from this machine, so the host key is not in known_hosts yet

1Check

Compare the fingerprint in the prompt with the list GitHub publishes. The ED25519 value there starts with SHA256:+DiY3wvvV6TuJJhbpZisF. If it matches, the server is the real one.

ssh -T git@github.com
# compare with https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints

2Fix

Type yes when the fingerprints match. ssh saves the key to ~/.ssh/known_hosts and does not ask again. If they do not match, answer no and stop.

# at the prompt
yes

3Verify

The second run connects without a prompt and prints your username. The command exits with code 1, which is expected because GitHub gives no shell.

ssh -T git@github.com

Confirmed by docs.github.com

Did this fix it?

Cause 2 of 2

A script, container or CI job cannot answer the prompt

1Check

ssh asks for confirmation by default (StrictHostKeyChecking ask). A non-interactive job has nobody to type yes. BatchMode turns those confirmation requests off.

grep -n -i -E 'StrictHostKeyChecking|BatchMode' ~/.ssh/config /etc/ssh/ssh_config

2Fix

Best: put GitHub's published host key entries into ~/.ssh/known_hosts (GitHub lists them for ssh-ed25519, ecdsa-sha2-nistp256 and ssh-rsa). Simpler: accept-new adds a key only the first time and still refuses a changed key.

# ~/.ssh/config
Host github.com
    StrictHostKeyChecking accept-new

3Verify

Run the job's git command once as the same user.

git ls-remote git@github.com:OWNER/REPO.git

Confirmed by man.openbsd.org

Did this fix it?

How do I stop it coming back?

  • Pre-load GitHub's published host keys into known_hosts when you build a server image or CI runner.
  • Do not use StrictHostKeyChecking no: it also accepts a changed key.
  • Run the first git command as the same user the deploy job uses, because known_hosts is per user.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.