Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to clone a repo in a non-interactive way. When cloning, git asks to confirm host's fingerprint:

The authenticity of host 'bitbucket.org (207.223.240.182)' can't be established.
RSA key fingerprint is 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40.
Are you sure you want to continue connecting (yes/no)? no

How do I force "yes" every time this questions pops up? I tried using yes yes | git clone ..., but it doesn't work.

EDIT: Here's a solution: Can I automatically add a new host to known_hosts? (adds entires to known_hosts with ssh-keyscan).

share|improve this question
    
Doesn't bitbucket have access to git via http or https ? Would be strange to not add it, considering the amount of nazi firewalls blocking everything but HTTP. –  BatchyX Feb 3 '13 at 9:51
    
Interesting to see that even after two years this question does not have a proper answer. There are few other cases where git will prompt, for example if you try to clone over http and the server is asking for basic_auth. How to do this in non-interactice mode? –  sorin Oct 23 '14 at 12:06
    
Adding the -q option (quiet) did it for me. Now I'm stuck automating the passphrase. –  Peter N Jun 21 at 21:34

7 Answers 7

On my end i fixed the issue with:

ssh-keyscan github.com >> ~/.ssh/known_hosts

I don't think that is the best solution, but it was a solution for me.

Just change the domain name.

share|improve this answer
    
@Falcon Momot, why did you edit my answer? Just to take a smile out and fix the "j" case? haha Are you a bot? –  kroe Nov 19 '14 at 14:15
3  
It came up in a review queue. Just minor edits for style. –  Falcon Momot Nov 19 '14 at 22:06
    
cool i did not even knew review queues exists... –  kroe Nov 20 '14 at 0:37

While I certainly understand that you want to automate such a process, doing so would be ill-advised. The reason why SSH and related networking subcomponents balk when using a secure protocol is to WARN a human that a system's public key is unknown. This is intentional - the user needs to explicitly inform the system the host is expected. You wouldn't want to auto accept every public key presented to you or part of the security in SSH or TLS/SSL could be compromised. One example is via a man-in-the-middle attack such as when a proxy software presents it's own key in the place of a host you expect.

Proceed with caution.

If you have no fear about the source of the code across the wire, you should explicitly and exclusively use the git:// protocol when cloning - it's authenticationless and in clear text.

share|improve this answer
1  
I can definitively see use cases where we need to enforce non-interactive uses of git clone... and that doesn't mean we require to accept any check (the fingerprint one in particular). In my case, I would be perfectly glad to fail automatically on such thing. –  vaab Apr 11 '14 at 11:04

I believe a better option here is to back up and empty your ~/.ssh/known_hosts file, manually perform the SSH connection, verifying the IP address and fingerprint, mv ~/.ssh/known_hosts ~/bitbucket_hosts, then use the contents of ~/bitbucket_hosts in your script to automatically append the known fingerprints to the known_hosts file (don't forget to restore the original ~/.ssh/known_hosts).

This step only needs to be performed once (on any machine, I believe), and once you have the fingerprints, you can incorporate it in to your automation script.

share|improve this answer

As Jeff Hall said, doing so is dangerous as it allows undetected man-in-the-middle attacks. However, you could use the StrictHostKeyChecking no option in ssh to disable checking the host keys. However, I'd be very careful with that option if I were you.

share|improve this answer
    
It also allows man-in-the-middle right? –  autra Jun 25 at 15:37

One nice option is to temporarily answer yes for the RSA fingerprint check on a specific clone:

yes | git clone http://bitbucket.org...

Edit: Doesn't work anymore. Tests now fail for me on fedora 19 with git 1.9.3:

$ yes | git clone git@bitbucket.org:freakypie/django-csv-tool.git
Cloning into 'django-csv-tool'...
The authenticity of host 'bitbucket.org (131.103.20.168)' can't be established.
RSA key fingerprint is 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40.
Are you sure you want to continue connecting (yes/no)? 
share|improve this answer
    
did not work for me with github git@ address –  kroe Oct 31 '14 at 4:51
1  
@kroe error message? write access on the repo? –  hobs Oct 31 '14 at 23:49
    
my bad, i did not post the error code. –  kroe Nov 2 '14 at 4:12
1  
Does not work for me, still stuck on Are you sure you want to continue connecting (yes/no)? –  Greg Jan 9 at 17:34
    
Doesn't work for me anymore either. Will edit. My test environment must've been flawed. ssh-keyscan from @kroe is still your best option. –  hobs Jan 9 at 19:17

Adding the key to .ssh/known_hosts appears to be the right thing to do.

Though when you automate the task you want to make sure the key is not already contained and added on each clone/pull tasks.

This snippet will only add the fingerprint if not already found:

if [ ! -n "$(grep "^bitbucket.org " ~/.ssh/known_hosts)" ]; then ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts 2>/dev/null; fi
share|improve this answer

None of the answer are secure. You have 2 options:

Use https protocol instead of git

It won't ask you for a fingerprint, because ssh is not involved, https (duh) is used instead. If you're using a minimalist image or Docker, you might need to install the ca-certificates package.

If you really want git protocol

Do you really need to add the key at runtime? This is totally not secure.

Before running your script, get the key from github (on your local machine):

ssh-keyscan github.com >> githubKey

Generate the fingerprint:

ssh-keygen -lf githubkey

And check it manually against those listed in this page (ok, there you trust https certificates and OpenSSL to bring you the original github website, but it's still a lot better than blindly accepting a public key).

Then, you harcode it in your script by adding in it:

echo '<copy paste the content of 'cat githubkey' on your machine>'  >> ~/.ssh/known_hosts

before the git clone.

The github public key will only change if they believe it was compromised (or not secure enough). If this is ever the case, you want your script to fail anyway.

share|improve this answer

Your Answer

 
discard

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.