I’ve got a vm running using vagrant, and I’m provisioning it with Chef. One of the steps involves cloning a git repo, but my ssh-key (on my host machine) has a passphrase on it.
When I run vagrant up, the process fails at the git clone step with the following error:
Permission denied (publickey). fatal: The remote end hung up unexpectedly
(The key has been added on the host machine, with the passphrase)
I tried to solve this with ssh agent forwarding by doing the following:
Added config.ssh.forward_agent = true to the VagrantFile
Added Defaults env_keep = "SSH_AUTH_SOCK to /etc/sudoers on the vm
Now, vagrant up still fails when it gets to the git clone part, but if I run vagrant provision after that, it passes. I’m guessing this is because the ssh configuration is set up when the vm is brought up and isn’t reloaded
I have tried to reload ssh after adjusting those two settings, but that hasn’t helped.
Any idea how to solve this?
Thanks.
As you noted, updating sudoers during the initial run is too late to be beneficial to that run as chef is already running under sudo by that point.
Instead I wrote a hacky recipe that finds the appropriate ssh socket to use and updates the SSH_AUTH_SOCK environment to suit. It also disables strict host key checking so the initial outbound connection is automatically approved.
Save this as a recipe that’s executed anytime prior to the first ssh connection (tested with Ubuntu but should work with other distributions):
Alternatively create a box with the sudoers update already in it and base your future VMs off of that.