Vagrant Provision Timeouts

Have you ever encountered this error?

Timed out while waiting for the machine to boot. This means that 
Vagrant was unable to communicate with the guest machine within 
the configured ("config.vm.boot_timeout" value) time period. 
If you look above, you should be able to see the error(s) that 
Vagrant had when attempting to connect to the machine. These errors 
are usually good hints as to what may be wrong. 
If you're using a custom box, make sure that networking is properly 
working and you're able to connect to the machine. It is a common 
problem that networking isn't setup properly in these boxes. 
Verify that authentication configurations are also setup properly, 
as well. 
If the box appears to be booting properly, you may want to increase 
the timeout ("config.vm.boot_timeout") value.

Or this?

An error occurred in the underlying SSH library that Vagrant uses. 
The error message is shown below. In many cases, errors from this 
library are caused by ssh-agent issues. Try disabling your SSH 
agent or removing some keys and try again. 
If the problem persists, please report a bug to the net-ssh project. 
timeout during server version negotiating

There could be multiple reasons this is happening, and I’ll walk through some steps to help diagnose and resolve the problem.

Why Does It Happen?

When Vagrant provisions, it tries to SSH into the virtual machine so that it can change things. It’s this attempt to connect to the VM that’s failing and generating the error. The Net SSH library used by Vagrant fails, causing the second error that mentions SSH Agents, and the longer error is Vagrants response.

The Vagrant SSH Key

Vagrant tries to authenticate its SSH connection using an insecure private key, but this can go wrong in several ways:

  • The virtual machine is still booting
    Running vagrant halt;vagrant up might fix this, or increasing the timeout
  • The current SSH Agent can interfere with the process
    Run export SSH_AUTH_SOCK="" to disable the SSH agent for the current session and retry
  • The public key never makes it into the VM’s authorised list, and the VM rejects the insecure private keys attempt to connect
    If you can run vagrant ssh you can add the public key manually to the authorised keys list e.g. `

    echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > .ssh/authorized_keys

    Be sure to use the official public key available from Vagrant themselves

If all else fails

Update Guest Additions

There’s a vagrant plugin to do this. When the additions are updated, you’ll need to turn the box off and on else you’ll get cryptic errors mounting filesystems. To install it, run:

vagrant plugin install vagrant-vbguest

Verify The Needed Vagrant Plugins are Installed

A number of Vagrant boxes int eh WordPress world and beyond rely on these plugins:

vagrant plugin install vagrant-hostsupdater
vagrant plugin install vagrant-triggers
vagrant plugin install vagrant-vbguest

Switch from Virtualbox to VMWare

While not free, it is more reliable than Virtualbox

Verify VirtualBox and Vagrant are up to date

Eliminate old bugs as a problem by updating to the latest versions of both. Be sure to check the Virtualbox guest additions are the latest version

Run Vagrant in Debug mode

Most messages are hidden from view, and that might include vital information. Use this command to provision Vagrant with a full verbose log file:

vagrant halt;vagrant up --provision --debug  &> vagrant.log

Use User/Password Auth Instead

You can configure Vagrant to use user pass authentication instead of SSH key auth. If you receive these errors but can still SSH into the VM then this may work for you

  config.ssh.insert_key = false
  config.ssh.paranoid = false
  config.ssh.keys_only = false
  config.ssh.username = "vagrant" # change as appropriate
  config.ssh.password = "vagrant"

Reprovision From Scratch

If you’re a fan of going nuclear, these commands will destroy your VM, and the base box, then reprovision twice:

vagrant destroy
vagrant box remove precise32
vagrant plugin install vagrant-hostsupdater
vagrant plugin install vagrant-triggers
vagrant plugin install vagrant-vbguest
vagrant up --provision
vagrant reload --provision

Adjust the box name and plugins as is necessary

One thought on “Vagrant Provision Timeouts

  1. Pingback: Vagrant Issues – Sue's Notes

Leave a Reply

Your email address will not be published. Required fields are marked *