Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm building a vagrant machine (Ubuntu 12.04) with the following requirements:

  • SSH access via Vagrant to a user with sudo-privileges.

I've generated public/private keys (via ssh-keygen) on the host and have moved the public key to the authorized_keys file on the guest. And I have tried a password-less SSH.

A couple of things happen I type vagrant ssh with password-enabled SSH keys:

  • I have to type my keyphrase in on the host machine to SSH into the Guest VM.
  • Each time I type in the correct keyphrase it is not accepted.

Which results in the I get the following error message:

SSH authentication failed! This is typically caused by the public/private
keypair for the SSH user not being properly set on the guest VM. Please
verify that the guest VM is setup with the proper public key, and that
the private key path for Vagrant is setup properly as well.

Then I tried password-less ssh.

vagrant ssh
vagrant@127.0.0.1's password: 

??

I never set up a vagrant user! It should be user@hostname as I had set it up and can confirm works when I boot the VM in VirtualBox.

How do I get private ssh keys to work properly with vagrant? What to do on the host, what to do on the guest?

Update

In VirtualBox the VM is live but I can't do any of the following commands from vagrant console in addition to the problems with vagrant ssh:

vagrant up vagrant halt

The only vagrant command that works is vagrant suspend. When I use it I can actually halt the machine via vagrant halt. Here is the output:

$ vagrant halt
[default] Attempting graceful shutdown of VM...
SSH authentication failed! This is typically caused by the public/private
keypair for the SSH user not being properly set on the guest VM. Please
verify that the guest VM is setup with the proper public key, and that
the private key path for Vagrant is setup properly as well.
share|improve this question
add comment

2 Answers

I am adding this solution for anyone who comes to this thread:

First open this file on the host machine:

$ sudo vim ~/.vagrant.d/boxes/<yourbox>/include/_Vagrantfile

Verify that config.ssh.private_key_path is set to your private key file. If not update that

ssh to vagrant box with default pwd

$ vagrant ssh (default pwd = ‘vagrant’]

Once in the box:

vagrant@lucid64:~$ sudo visudo -f .ssh/authorized_keys

Add your public key to this file and save the file, and exit the box

vagrant@lucid64:~$ exit

Back to the local machine

$ vagrant halt
$ vagrant up

This worked for me

share|improve this answer
    
Thanks for this - I am wondering though what if it is possible to ssh into a box as user different from vagrant and use the pub/priv key pair? Further you can set the path to the desired private ssh key from the Vagrantfile like so? –  rhodee Aug 16 '12 at 13:09
add comment

Try copying the vagrant insecure public key into the file .ssh/authorized_keys into the guest box.

Hope this resolves your ssh issue.

If you want to make it secure then you can do so by copying your own .ssh/id_rsa.pub into the aforementioned file. And setting the

config.ssh.private_key_path = '~/.ssh/id_rsa'

in your Vagrantfile.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.