title: How can I get GIT/SSH to look for "known_hosts" in a specific location?
body: <p>I am using GIT as part of an automated build process on Ubuntu Linux. Because it's an automated build process, it is preferrable to have all configuration in version control, so that I don't have to log in to each build agent when the configuration changes.</p>
  
  <p>To get this to work, I have a private key (with read-only repo access) and a known_hosts file checked in to version control.</p>
  
  <p>I set the HOME environment variable to a location within my version control (build/ssh_home) in order to allow GIT to locate my known_hosts file (build/ssh_home/.ssh/known_hosts).</p>
  
  <p>I use the following command to "activate" the private key and pull from GIT. The "git clone" step is similar.</p>
  
  <pre><code>ssh-agent bash -c "echo $HOME; ssh-add '${deploymentKey}' &gt;/dev/null 2&gt;&amp;1; git pull ${repository} --quiet"
  </code></pre>
  
  <p>This works on Windows. However, on Ubuntu Linux, this is not sufficient.</p>
  
  <p>The "HOME" environment variable is set as follows (in a bash script)</p>
  
  <pre><code>export HOME=`pwd`/build/ssh_home
  </code></pre>
  
  <p>However, it's clearly not using the right known_hosts file, it's still trying to use the one in ~/.ssh/known_hosts, evidenced by the path cited in the message below.</p>
  
  <pre><code>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)? yes 
  Failed to add the host to the list of known hosts (/home/myusername/.ssh/known_hosts).
  </code></pre>
  
  <p><strong>How can I get GIT (SSH) to use a known_hosts file in a specific location (not in my home directory)?</strong></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Permissions on my "build/ssh_home" directory (requested in comments)</p>
  
  <pre><code>ls -la build/ssh_home
  total 16
  drwx------  3 ben ben 4096 Jun 18 10:52 .
  drwxrwxr-x 39 ben ben 4096 Jun 18 10:52 ..
  -rw-------  1 ben ben  209 Jun 18 10:52 readme.txt
  drwx------  2 ben ben 4096 Jun 18 10:52 .ssh
  </code></pre>
  
  <p>Permissions on build/ssh_home/.ssh</p>
  
  <pre><code>ls -la build/ssh_home/.ssh
  total 12
  drwx------ 2 ben ben 4096 Jun 18 10:52 .
  drwx------ 3 ben ben 4096 Jun 18 10:52 ..
  -rw------- 1 ben ben 2402 Jun 18 10:52 known_hosts
  </code></pre>
  
  <p>Permissions on my "~/.ssh" directory (requested in comments)</p>
  
  <pre><code>myusername@myhostname:~$ ls -la ~/.ssh
  total 24
  drwxr-xr-x  2 root root 4096 Jun 29 10:28 .
  drwxr-xr-x 16 ben  ben  4096 May 21 15:39 ..
  -rw-r--r--  1 root root  427 May 19 11:27 authorized_keys
  -rw-------  1 root root 1679 May 19 11:27 bitbucket
  -rw-r--r--  1 root root  398 May 19 11:27 bitbucket.pub
  -rw-r--r--  1 root root   63 May 19 11:27 config
  </code></pre>