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条回答
Summer. ? 凉城
2楼-- · 2019-01-05 07:40

Been beating my head on this for the last couple of days on a repackaged base box. (Mac OS X, El Capitan)

Following @Radek 's procedure I did 'vagrant ssh-config' on the source box and got:

...
/Users/Shared/dev/<source-box-name>/.vagrant/machines/default/virtualbox/private_key
...

On the new copy, that command gave me:

...
IdentityFile /Users/<username>/.vagrant.d/insecure_private_key
...

So, I just added this line in the new copy:

...
config.ssh.private_key_path = "/Users/Shared/dev/<source-box-name>/.vagrant/machines/default/virtualbox/private_key"
...

Not perfect, but I can get on with my life.

查看更多
够拽才男人
3楼-- · 2019-01-05 07:41

for me, this was resolved by changing the permissions on .ssh folder in vagrant home directort (i.e. "~vagrant/.ssh"). I think I messed up the permissions when I was setting up ssh keys for my application.

It seems that 'authorized_keys' file must be 'rw' only for 'vagrant' user so "chmod 600 authorized_keys"; the same goes for the directory itself and its parent:

so:

chmod 600 authorized_keys
chmod 700 .
chmod 700 ..

It was only after I had all these permissions restored that vagrant ssh started to work again.

I think it's something to do with ssh security. It refuses to recognise certificates if they are any way accessible beyond the current user, so vagrants attempts to login are thus rejected.

查看更多
爷、活的狠高调
4楼-- · 2019-01-05 07:41

Mac Solution:

  1. Added local ssh id_rsa key to vagrant private key

    vi /Users//.vagrant/machines/default/virtualbox/private_key

    /Users//.ssh/id_rsa

  2. copied public key /Users//.ssh/id_rsa.pub on vagrant box authorized_keys

ssh vagrant@localhost -p 2222 (password: vagrant) ls -la cd .ssh

  1. chmod 0600 ~/.ssh/authorized_keys

  2. vagrant reload

Problem resolved.

Thanks to

查看更多
Juvenile、少年°
5楼-- · 2019-01-05 07:47

I solved this problem by running commands on windows 7 CMD as given in this here is the link last post on this thread,

https://github.com/mitchellh/vagrant/issues/6744

Some commands that will reinitialize various network states:
Reset WINSOCK entries to installation defaults : netsh winsock reset catalog
Reset TCP/IP stack to installation defaults : netsh int ip reset reset.log
Flush DNS resolver cache : ipconfig /flushdns
Renew DNS client registration and refresh DHCP leases : ipconfig /registerdns
Flush routing table : route /f
查看更多
在下西门庆
6楼-- · 2019-01-05 07:48

First of all you should remove the autogenerated insecure_private_key file, then regenerate this file by typing

vagrant ssh-config

then

vagrant halt
vagrant up

It should work

查看更多
SAY GOODBYE
7楼-- · 2019-01-05 07:48

I am using Vagrant with a Puphpet setup from May 2015 and had this problem. It appears that the configuration that was generated didn't handle Vagrant 1.7.4 (or maybe a bit earlier?) behavior of regenerating ssh keys if it detects an insecure key.

I solved it by adding the following in my Puphpet generated Vagrantfile (local setup) inside the "if File.file?(customKey)" clause:

config.ssh.insert_key = false

Reference commit

查看更多
登录 后发表回答