Skip to content

Instantly share code, notes, and snippets.

@shsteven
Created February 18, 2016 05:03
Show Gist options
  • Save shsteven/7c90b88d3c796ad391f0 to your computer and use it in GitHub Desktop.
Save shsteven/7c90b88d3c796ad391f0 to your computer and use it in GitHub Desktop.
Vagrant copy pre-generated ssh keys
# Copy local user's SSH key to /home/vagrant/.ssh/id_rsa
if File.exists?(File.join("ssh", "id_rsa"))
config.vm.provision :shell, :inline => "echo 'Copying local Git SSH Key to VM...'"
config.vm.provision :shell, :inline => "mkdir -p /home/vagrant/.ssh && cp /vagrant/ssh/* /home/vagrant/.ssh/ && chmod 600 /home/vagrant/.ssh/*"
config.vm.provision :shell, :inline => "sudo chown `id -u vagrant`:`id -g vagrant` /home/vagrant/.ssh/*"
else
# Else, throw a Vagrant Error. Cannot successfully startup without a GitHub SSH Key!
raise Vagrant::Errors::VagrantError, "\n\nERROR: GitHub SSH Key not found at ~/.ssh/id_rsa\n\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment