Cloning from private git on vagrant provision?
<p>I am wanting to retrieve a project from a private project in bitbucket while provisioning a Linux based Vagrant box, but I am running this is failing.</p>

<p>The operation is of the form:</p>

<pre><code>cd /tmp

git clone ssh://git@bitbucket.org/myuser/myproject.git
</code></pre>

<p>In my Vagrant file I have specified:</p>

<pre><code> config.ssh.forward_agent = true
</code></pre>

<p>The output of the operation is:</p>

<pre><code>==&gt; default: Cloning into 'myproject'...
==&gt; default: Host key verification failed.
==&gt; default: fatal: Could not read from remote repository.
==&gt; default: 
==&gt; default: Please make sure you have the correct access rights
==&gt; default: and the repository exists.
</code></pre>

<p>If I <code>vagrant ssh</code> into the box and then attempt the same git clone I have no issues cloning the repository.</p>

<p>I have tried adding the following (where "ubuntu" is the default user for box "ubuntu/xenial64"):</p>

<pre><code>sudo -H -u ubuntu ssh-keygen -R bitbucket.org
sudo -H -u ubuntu git clone ssh://git@bitbucket.org/myuser/myproject.git
</code></pre>

<p>This just results in:</p>

<pre><code>==&gt; default: Host bitbucket.org not found in /home/ubuntu/.ssh/known_hosts
==&gt; default: Cloning into 'myproject'...
==&gt; default: Host key verification failed.
==&gt; default: fatal: Could not read from remote repository.
==&gt; default: 
==&gt; default: Please make sure you have the correct access rights
==&gt; default: and the repository exists.
</code></pre>

<p>I also tried adding the following to the script, but no change:</p>

<pre><code>ssh-keyscan -H bitbucket.com &gt;&gt; ~/.ssh/known_hosts
sudo -H -u ubuntu ssh-keyscan -H bitbucket.com &gt;&gt; ~/.ssh/known_hosts
</code></pre>

<p>Vagrant configuration:</p>

<pre><code>Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "ubuntu/xenial64"

  config.vm.synced_folder './', '/vagrant', disabled: false, create: true

  config.ssh.forward_agent = true

  config.vm.provider :virtualbox do |vb, override|
    vb.name = 'myproject-dev-standalone'    

    # Web server HTTP front end
    override.vm.network :forwarded_port, guest: 80, host: 10080
    # Web server HTTPS front end    
    override.vm.network :forwarded_port, guest: 443, host: 10443

    override.vm.provision :shell do |s|
      s.path = "provision/install.sh"
      s.privileged = false
    end
  end

end
</code></pre>

<p>Can anyone suggest of way to be able to <code>git clone</code> during provision, without hard-coding the password into the install script?</p>