Vagrant ssh authentication failure

2019-01-05 07:18发布

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 for All Users.

  • Created the ~/.ssh directory with 0700 permissions.

  • Created the ~/.ssh/authorized_keys file with 0600 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.

27条回答
对你真心纯属浪费
2楼-- · 2019-01-05 07:55

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.

查看更多
三岁会撩人
3楼-- · 2019-01-05 07:56

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.

enter image description here

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:

default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key

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.

查看更多
冷血范
4楼-- · 2019-01-05 07:56

I resolved the issue in the following manner. 1. Create new SSH key using Git Bash

$ ssh-keygen -t rsa -b 4096 -C "vagrant@localhost"
# Creates a new ssh key, using the provided email as a label
Generating public/private rsa key pair.
  1. 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]

  2. 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]

  3. To connect to your Vagrant VM type following command

    ssh vagrant@localhost -p 2222

When you get following message type “yes” and press enter.

The authenticity of host 'github.com (192.30.252.1)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
  1. Now to establish a SSH connection type : $ vagrant ssh

  2. 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.

  3. Change permission on SSH folder and authorized_keys file in Vagrant VM
  4. Restart vagrant with : $ vagrant reload
查看更多
混吃等死
5楼-- · 2019-01-05 07:58

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.

查看更多
Summer. ? 凉城
6楼-- · 2019-01-05 08:02

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.

查看更多
甜甜的少女心
7楼-- · 2019-01-05 08:03

This has happened to me several times and the way I solved it was :

  1. Check and make sure your Vagrantfile has the correct private key path :

    config.ssh.private_key_path = "/home/razvan/.ssh/id_rsa"

  2. Execute > vagrant ssh command in a linux terminal

  3. 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.

  1. Reload Vagrant :

    vagrant reload

Hope this helps someone else. Cheers!

查看更多
登录 后发表回答