Vagrant – Authentication failure

Depending on the vagrant version and how you build/package boxes, you may know the Authentication failure after command “$ vagrant up“. Here now two simple tips, how to prevent or fix it.

Prevention

If you build on an existing box you should not allow Vagrant to automatically insert a new key pair.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure('2') do |config|

  config.ssh.insert_key = false
  ...

end

Workaround

If the problem already exists…

# start VM (local)
$ vagrant up
...
default: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot...
...

# login via password authentication (local -> VM)
$ vagrant ssh

# start edit authorized_keys (VM)
[vagrant@acme ~]$ vim .ssh/authorized_keys

# add latest key from https://github.com/mitchellh/vagrant/blob/master/keys/vagrant.pub and save

# leave vm (VM -> local)
$ exit

# stop VM (local)
$ vagrant halt

On command “$ vagrant halt” Vagrant will automatically insert a new keypair.