Vagrant Problem : SSH authentication failure

If starting your vagrant machine you see something like this

    default: Error: Connection timeout. Retrying...
    default: Error: Connection timeout. Retrying...
    default: Error: Connection timeout. Retrying...
    default: Error: Authentication failure. Retrying...
    default: Error: Authentication failure. Retrying...
    default: Error: Authentication failure. Retrying...
    default: Error: Authentication failure. Retrying...
    default: Error: Authentication failure. Retrying...

Your vagrant machine have an issue related with the ssh keys used by the vagrant user to connect the host with the guest.

In my experience, this has been a surprisingly frequent problem with new vagrant machines. By far the easiest way to solve it, instead of altering the configuration itself, has been creating the required ssh keys manually on the client, then using the private key on the host.

This is one possible path to solve this issue and avoid to recreate the machine.

Log in to vagrant machine: vagrant ssh, use default password vagrant.

host$ ssh vagrant@yourmachine.ip.or.hostname

Note : gest$ and host$ is to reflect where you should run the command, is not part of the command it self. Think before copy/paste.

Create ssh keys: for example:

guest$ ssh-keygen -t rsa -b 4096 -C "vagrant"

Rename the public key file (by default id_rsa.pub), overriding the old one

guest$ mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

Reload ssh service in case needed:

guest$ sudo service ssh reload

Copy the private key file (by default id_rsa) to the host machine: for instance, use a fine combination of cat and clipboard, cat .ssh/id_rsa, paint and copy (better ways must exist, go invent one!).

Logout from the vagrant machine: logout.

Find the current private key used by vagrant by looking at its configuration: vagrant ssh-config (look for instance ÌdentityFile “/[…]/private_key”.

Here you have two options

Replace the current private key with the one you created at the host machine: for example, nano /[…]/private_key and paste from the clipboard, if all else fails. Note, however, that if your private_key is not project specific but shared by multiple vagrant machines, you better configure the path yourself in order to not break other perfectly working machines!

Or, Changing the path is as simple as adding a line config.ssh.private_key_path = “path/to/private_key” into the Vagrantfile. Note that this will force all your coworkers to have the key in the sample place!

Test the setup, “vagrant ssh” should now work :). If not, review the previous steps and if that doesn’t work neither, destroy your machine and create a new machine 🙁

Should that be the case, congratulate yourself, logout, run vagrant provision if needed and carry on with the meaningful task at hand.

0 comments on “Vagrant Problem : SSH authentication failureAdd yours →

Leave a Reply

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