Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot clone private repo from Vagrant provision file

I have vagrant provision script containing shell commands. When I try to clone private repo via git and private\public keys within this script I get an error:

Cloning into 'brand.api'...

Stderr from the command:

stdin: is not a tty
dpkg-preconfigure: unable to re-open stdin: No such file or directory
Host key verification failed.
fatal: The remote end hung up unexpectedly

But when I exclude git clone ... command from provision script and call it myself within vagrant box everything is ok.

Here is the provision file:

#setting up Git
apt-get install -y git
mkdir ~/.ssh
mkdir ~/bin
cp /vagrant/bin/git-ssh.sh  ~/bin
cp /vagrant/keys/mygit.key ~/.ssh/mygit.key 
cp /vagrant/keys/mygit.pub ~/.ssh/mygit.pub

chmod 600 ~/.ssh/*
echo 'export GIT_SSH=~/bin/git-ssh.sh' >> ~/.bashrc
source ~/.bashrc

#installing brand-api
git clone git@****.ru:brand.api.git

What's the problem?

UPDATED

After adding git repo host to known_hosts I get this:

Stderr from the command:

stdin: is not a tty
dpkg-preconfigure: unable to re-open stdin: No such file or directory
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly

But if I login to my box via vagrant ssh and try to clone everything is OK.

like image 534
trerums Avatar asked May 29 '14 13:05

trerums


2 Answers

The SSH key of the git server is not known/trusted. When you clone the repo manually on the VM, you get a prompt asking to verify the fingerprint, right?

You can either skip the host key verification in ~/.ssh/config (or globally in /etc/ssh/config or alike):

Host git.example.com
  StrictHostKeyChecking no

Or you can add the key in advance to ~/.ssh/known_hosts (or /etc/ssh/ssh_known_hosts). For example:

ssh-keyscan -H git.example.com >> ~/.ssh/known_hosts
like image 54
tmatilai Avatar answered Oct 12 '22 19:10

tmatilai


This works to me..

Try put this in your provision.sh:

sudo -u vagrant git clone git@****.ru:brand.api.git

Instead of:

git clone git@****.ru:brand.api.git
like image 21
Everton Z. P. Avatar answered Oct 12 '22 19:10

Everton Z. P.