Vagrant Problem : SSH authentication failure

If starting your vagrant machine you see something like this

[cc lang=”bash” width=”100%”]
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…
[/cc]

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.

[cc lang=”bash” width=”100%”]
host$ ssh [email protected]
[/cc]

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:

[cc lang=”bash” width=”100%”]
guest$ ssh-keygen -t rsa -b 4096 -C “vagrant”
[/cc]

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

[cc lang=”bash” width=”100%”]
guest$ mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
[/cc]

Reload ssh service in case needed:

[cc lang=”bash” width=”100%”]
guest$ sudo service ssh reload
[/cc]

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.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.