Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to do a git clone trough a bash script, but the first time that I run the script and the server is not known yet the script fails. I have something like this:

yes | git clone git@github.com:repo/repoo.git
The authenticity of host 'github.com (' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? 

But it's ignoring the yes. Do you know how to force git clone to add the key to the known hosts?

share|improve this question
What about echo yes | git clone git@github.com:repo/repoo.git? – asfallows Aug 16 '11 at 20:33
@asfallows, @Rafael: echo yes is not a good approach: the second time you run the command, ssh won't ask if you want to continue because the server key will already be known. – Gilles Aug 16 '11 at 23:27
up vote 19 down vote accepted

Add the following to your ~/.ssh/config file:

Host github.com
    StrictHostKeyChecking no

Anything using the open-ssh client to establish a remote shell (with the git client does) should skip the key checks to github.com.

This is actually a bad idea since any form of skipping the checks (whether you automatically hit yes or skip the check in the first place) creates room for a man in the middle security compromise. A better way would be to retrieve and validate the fingerprint and store it in the known_hosts file before needing to run some script that automatically connects.

share|improve this answer
With a strong preference to retrieve and validate the fingerprint and store it in the known_hosts file before. – Gilles Aug 16 '11 at 23:27
Thanks a lot for your answer, I ended up following the approach of adding the finger print in the known_hosts. It's like more secure :) – Rafael Aug 19 '11 at 0:08
Oh I'm using puppet to do this. If someone is interested in using it here is the recipe: gist.github.com/1155725 – Rafael Aug 19 '11 at 0:49

yes outputs y. RSA key acceptance needs yes. You could try yes yes | git clone git@github.com:repo/repoo.git so yes outputs yes instead of y.

share|improve this answer
For some reason, that didn't work with git clone, for me. – Matt V. Dec 15 '11 at 23:17
Neither it worked for me. Also echo "yes" | ... doesn't. I think git doesn't accept piping. Maybe only in some version? – udondan Feb 16 '15 at 10:19

I've run into this issue before. Albeit it was on a Windows machine but we needed to use ssh to connect to a remote host. We ran into the same problem that the first connect always failed because it wouldn't recognize the keys.

I solved it by connecting manually and finding the registry key and importing it at the beginning of the script. In Linux it should be the same general idea: you want to add this server to a list of trusted hosts so that ssh won't ask you if you trust him every time.

Once you connect manually, find the key file and add it to your known_hosts file. This way ssh will look over that file, assume you know what you're doing and proceed without asking you about the fingerprint.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.