The problem with ssh authentication:
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Error: Connection timeout. Retrying...
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...
I can Ctrl+C
out of the authentication loop and then successfully ssh in manually.
I performed the following steps on the guest box:
Enabled
Remote Login
forAll Users
.Created the
~/.ssh
directory with0700
permissions.Created the
~/.ssh/authorized_keys
file with0600
permissions.Pasted this public key into
~/.ssh/authorized_keys
I've also tried using a private (hostonly) network instead of the public (bridged) network, using this line in the Vagrantfile:
config.vm.network "private_network", ip: "172.16.177.7"
I get the same output (except Adapter 2: hostonly
) but then cannot ssh in manually.
I also tried config.vm.network "private_network", ip: "10.0.0.100"
.
I also tried setting config.ssh.password
in the Vagrantfile. This does output SSH auth method: password
but still doesn't authenticate.
And I also tried rebuilding the box and rechecking all the above.
It looks like others have had success with this configuration, so there must be something I'm doing wrong.
I found this thread and enabled the GUI, but that doesn't help.
Between all of the responses here, there are lots of good things to try. For completeness, if you
ssh vagrant@localhost -p 2222
as @Bizmate suggests, and it fails, be sure you have
AllowUsers vagrant
in the
/etc/ssh/sshd_config
of your guest/vagrant machine.This might be the last answer in the list but this worked for me and I did not find this answer anywhere, I found it my self after 2 days of researches so you've better try this if nothing else worked for you until now.
In my case the problem came from my VirtualBox. I don't know for what reason an option was disabled and it should have been enabled.
As you can see in the image, there were some network problems with my VirtualBox and what I had to do in order to fix this problem was to select my machine, press on settings, network tab and after that make sure that the option Cable Connected was selected. In my case this option was not selected and I it failed at this step:
First I thought that the port is already in use, after that I reinstalled Vagrant and I also tried other things but none of them worked for me.
I resolved the issue in the following manner. 1. Create new SSH key using Git Bash
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
Enter a file in which to save the key (/Users/[you]/.ssh/id_rsa): [Press enter]
At the prompt, type a secure passphrase. You can leave empty and press enter if you do not need a passphrase.
Enter a file in which to save the key (/Users/[you]/.ssh/id_rsa): [Press enter]
To connect to your Vagrant VM type following command
ssh vagrant@localhost -p 2222
When you get following message type “yes” and press enter.
Now to establish a SSH connection type : $ vagrant ssh
Copy the host public key into authorized_keys file in Vagrant VM. For that, go to “Users/[you]/.ssh” folder and copy the content in id_rsa.pub file in host machine and past into “~/.ssh/authorized_keys” file in Vagrant VM.
Make sure your first network interface is NAT. The other second network interface can be anything you want when you're building box. Don't forget the Vagrant user, as discussed in the Google thread.
Good luck.
Just for those people that have been idiots like me, or have had something odd happen to their vagrant machine. This error can also occur when you changed the permissions of the vagrant user's home directory (deliberately or by accident).
You can log in instead (as described in other posts) using the password ('vagrant') and then run the following command to fix the permissions.
sudo chown -R vagrant:vagrant /home/vagrant
Then you should be able to log in again without entering the password.
TL;DR: The permissions on your vagrant home folder are wrong.
This has happened to me several times and the way I solved it was :
Check and make sure your Vagrantfile has the correct private key path :
config.ssh.private_key_path = "/home/razvan/.ssh/id_rsa"
Execute > vagrant ssh command in a linux terminal
On your vagrant machine go to
cd /home/vagrant/.ssh
and check if the ssh key in the authorized_keys file is the same as the one you have on your local machine in ~/.ssh/id_rsa.pub. If not replace the one from your vagrant authorized_keys with the one on your local machine found in ~/.ssh/id_rsa.pub.
Reload Vagrant :
vagrant reload
Hope this helps someone else. Cheers!