git - 无法从 Vagrant 配置文件克隆私有(private)仓库

标签 git ssh vagrant ssh-keys

我有包含 shell 命令的 vagrant provision 脚本。当我尝试通过 git 和 private\public key 在此脚本中克隆私有(private) repo 时,出现错误:

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

但是当我从配置脚本中排除 git clone ... 命令并在 vagrant box 中自己调用它时,一切正常。

这是配置文件:

#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

有什么问题?

已更新

将 git repo host 添加到 known_hosts 后,我得到了这个:

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

但是如果我通过 vagrant ssh 登录到我的盒子并尝试克隆一切就OK了。

最佳答案

git 服务器的 SSH key 未知/不可信。当您在 VM 上手动克隆 repo 时,您会收到要求验证指纹的提示,对吗?

您可以在 ~/.ssh/config 中跳过主机 key 验证(或在 /etc/ssh/config 或类似的全局中):

Host git.example.com
  StrictHostKeyChecking no

或者您可以预先将 key 添加到~/.ssh/known_hosts(或/etc/ssh/ssh_known_hosts)。例如:

ssh-keyscan -H git.example.com >> ~/.ssh/known_hosts

关于git - 无法从 Vagrant 配置文件克隆私有(private)仓库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23935138/

相关文章:

git 审查不起作用?但是我可以在推送时看到我的更改。我究竟做错了什么?

ruby - 推送预提交 git 钩子(Hook) (Rubocop)

mysql - Vagrant mysql 与 MySQLWB

ssh - ssh proxycommand -W, nc, exec nc 有什么区别

python - 从主机浏览器访问 VirtualBox/Vagrant 机器上的 django 服务器?

git - IntelliJ IDEA git 集成和暂存区(索引)

git - 将差异文件中的更改提取到当前分支

ssh - Ansible ssh 授予权限被拒绝错误

php - 如何通过 Puppet(在 Vagrant 上)连接 Nginx 和 PHP?

wordpress - 加快Vagrant上主机和 guest 之间的同步延迟(NFS同步文件夹)