SSH to GitHub asks to confirm the host, or hangs on that prompt
The 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.
Fix it fast
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.com2Match what you see, then jump to its fix
- 1
The 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
git 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
- 1
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-fingerprints2Fix
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
yes3Verify
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.comConfirmed by docs.github.com
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_config2Fix
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-new3Verify
Run the job's git command once as the same user.
git ls-remote git@github.com:OWNER/REPO.gitConfirmed by man.openbsd.org
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
Security
AuthenticationException: your certificate validation callback returned false
System.Security.Authentication.AuthenticationException
This message means a validation callback was installed, yours or one a library added, and it returned false.
3 causes, each with a fixSecurity
SSH to an EC2 instance fails with Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
ec2-user@ec2-203-0-113-25.compute-1.amazonaws.com: Permission denied (publickey).
On EC2 this error almost always means the instance did not accept your key for that user.
3 causes, each with a fixSecurity
gcloud init cannot finish the sign-in step
Enter authorization code
gcloud init signs in through a browser.
3 causes, each with a fixSecurity
A GitHub Actions SSH deploy step cannot log in to the server
ssh: handshake failed: ssh: unable to authenticate
The runner reached your server but the server refused the login.
4 causes, each with a fixSecurity
A GUI program over SSH says it cannot open the display
cannot open display:
ssh must forward X11 and the remote sshd must allow it.
3 causes, each with a fixSecurity
PHP LDAP in Laravel fails with Can't contact LDAP server over TLS
unable to get local issuer certificate
PHP's LDAP client uses OpenLDAP's settings.
3 causes, each with a fix