Skip to content

Instantly share code, notes, and snippets.

@amccarty
Created November 5, 2015 17:32
Show Gist options
  • Save amccarty/2137ae65ddada56c0865 to your computer and use it in GitHub Desktop.
Save amccarty/2137ae65ddada56c0865 to your computer and use it in GitHub Desktop.
Add public key to vagrant's authorized_keys
id_rsa_key_pub = File.read(File.join(Dir.home, ".ssh", "id_rsa.pub"))
config.vm.provision :shell,
:inline => "echo 'appending SSH Pub Key to ~vagrant/.ssh/authorized_keys' && echo '#{id_rsa_key_pub }' >> /home/vagrant/.ssh/authori
zed_keys && chmod 600 /home/vagrant/.ssh/authorized_keys"
config.ssh.insert_key = false
@mohsenSy
Copy link

Hi, thanks for the useful gist but there is one problem here, you need to add chown vagrant:vagrant /home/vagrant/.ssh/authorized_keys in order for it to work, because with these command the file is owned by root and has 0600 permissions which prevent vagrant user from reading it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment