p3bj2a
Last Updated: February 07, 2017
·
23.92K
· jabclab
4f4bf0fbd4cc6de6159d78f9f9fb3aa6

Cloning from GitHub in Vagrant using SSH agent forwarding

For our development environments we are working predominantly in Vagrant so that we all have a consistent dev env.

One challenge which arose was how to clone from GitHub within the Vagrant-created VM. We achieved this using ssh agent forwarding:

1. Add your SSH key which is tied to GitHub account to host ssh-agent

key_file=~/.ssh/id_rsa

# Add if not already added
[[ -z $(ssh-add -L | grep $key_file) ]] && ssh-add $key_file

2. Enable SSH agent forwarding in your Vagrantfile

config.ssh.forward_agent = true

You will then be able to do the following:

$ vagrant ssh
[vagrant@localhost ~]$ ssh -T git@github.com
Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.

(as usual you'll have to authorise GitHub's public RSA key so it can be added to the ~/.ssh/known_hosts).

Say Thanks
Respond

5 Responses
Add your response

12908
369c83603d93d80b7c6842d9870dd96c

Awesome! Works flawlessly.

over 1 year ago ·
15520
B29a5fdc5c540d232adb367f2c9bb0a0

Within our Vagrant environment, I run the following bash script to prevent the need to authorize any SSH keys during the provisioning process:

!/bin/bash

touch /home/vagrant/.ssh/config
chown vagrant:vagrant /home/vagrant/.ssh/config
chmod 600 /home/vagrant/.ssh/config

cat << 'EOF' >> /home/vagrant/.ssh/config

StrictHostKeyChecking no

EOF

exit 0

over 1 year ago ·
18135
None

Sweeeeet

over 1 year ago ·
22681
None

how can i execute git clone command during vagrant up without specifying username and password in the vagrantfile itself.
git clone -b develop https://username:password@github.com/repo.git. i added this command in vagrant file and when i do vagrant up, able to clone the repository. But I would like to change this command such that it works for every user who has vagrant file.

over 1 year ago ·
22919
None

Where should you add this? Host-machine, file etc?

key_file=~/.ssh/id_rsa

# Add if not already added
[[ -z $(ssh-add -L | grep $key_file) ]] && ssh-add $key_file

</code>

over 1 year ago ·
Filed Under