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:50

This the all correct steps that I followed for fix this bellow issue occurred when vagrant up command run.

These are the steps that I followed

  1. create a folder. e.g F:\projects
  2. Open this folder in git bash and run this command ssh-keygen -t rsa -b 4096 -C "your_email@example.com" (put a valid email address)
  3. Then generating key pair in two separate files in the project folder. e.g project(private key file), project.pub (public key file)
  4. Go to this location C:\Users\acer.vagrant.d and find file insecure_private_key
  5. Get backup of the file and copy the content of newly created private key and paste it in insecure_private_key file. Then copy insecure_private_key and paste it in this location too.
  6. Now vagrant up in your project location. after generating above issue type vagrant ssh and go inside giving username, password. (in default username and password is set as vagrant)
  7. Go inside to this location cd /home/vagrant/.ssh and type mv authorized_keys authorized_keys_bk
  8. Then type ls -al and type vi authorized_keys for open authorized_keys file vi editor.
  9. Open generated public key from notepad++ (project.pub) and copy content Then press i on git bash to enable insert mode on vi editor and right click and paste. After press escape to get out from insert mode
  10. :wq! for save the file and type ls -al
  11. Then permissions are set like bellow no need to change drwx------. 2 vagrant vagrant 4096 Feb 13 15:33 . drwx------. 4 vagrant vagrant 4096 Feb 13 14:04 .. -rw-------. 1 vagrant vagrant 743 Feb 13 14:26 authorized_keys -rw-------. 1 root root 409 Feb 13 13:57 authorized_keys_bk -rw-------. 1 vagrant vagrant 409 Jan 2 23:09 authorized_keys_originial Otherwise type chmod 600 authorized_keys and type this command too chown vagrant:vagrant authorized_keys
  12. Finally run the vagrant halt and vagrant up again.

************************THIS IS WORK FINE FOR ME*******************************

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-05 07:52

Problem I was getting the ssh authentication errors, on a box I provisioned. The original was working ok.

The problem for me was I was missing a private key in .vagrant/machines/default/virtualbox/private_key. I copied the private key from the same relative location from the original box and Viola!

查看更多
forever°为你锁心
4楼-- · 2019-01-05 07:52

Simple:

homestead destroy
homestead up

Edit (Not as simple as first thought):

The issue was that new versions of homestead use php7.0 and some other stuff. To avoid this mess up make sure you set the verison in Homestead.yml:

version: "0"
查看更多
手持菜刀,她持情操
5楼-- · 2019-01-05 07:53

If you are using default SSH setup in your VagrantFile and started seeing SSH authentication errors after re-associating your VM box due to crash, try replacing public key in your vagrant machine.

Vagrant replaces public key associated with insecure private key pair at each log out due to security reasons. If you didn't properly shut down your machine, public/private key pair can go out of sync, causing SSH authentication error.

To resolve this issue, simply load up the current insecure private key and then copy the public key pair into your VM's authorized_keys file.

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

For general information: by default to ssh-connect you may simply use

user: vagrant password: vagrant

https://www.vagrantup.com/docs/boxes/base.html#quot-vagrant-quot-user

First, try: to see what vagrant insecure_private_key is in your machine config

$ vagrant ssh-config

Example:

$ vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/konst/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

http://docs.vagrantup.com/v2/cli/ssh_config.html

Second, do: Change the contents of file insecure_private_key with the contents of your personal system private key

Or use: Add it to the Vagrantfile:

Vagrant.configure("2") do |config|
  config.ssh.private_key_path = "~/.ssh/id_rsa"
  config.ssh.forward_agent = true
end
  1. config.ssh.private_key_path is your local private key
  2. Your private key must be available to the local ssh-agent. You can check with ssh-add -L. If it's not listed, add it with ssh-add ~/.ssh/id_rsa
  3. Don't forget to add your public key to ~/.ssh/authorized_keys on the Vagrant VM. You can do it by copy-and-pasting or using a tool like ssh-copy-id (user: root password: vagrant port: 2222) ssh-copy-id '-p 2222 root@127.0.0.1'

If still does not work try this:

  1. Remove insecure_private_key file from c:\Users\USERNAME\.vagrant.d\insecure_private_key

  2. Run vagrant up (vagrant will be generate a new insecure_private_key file)

In other cases, it is helpful to just set forward_agent in Vagrantfile:

Vagrant::Config.run do |config|
   config.ssh.forward_agent = true
end

Useful:

Configurating git may be with git-scm.com

After setup this program and creating personal system private key will be in yours profile path: c:\users\USERNAME\.ssh\id_rsa.pub

PS: Finally - suggest you look at Ubuntu on Windows 10

查看更多
劳资没心,怎么记你
7楼-- · 2019-01-05 07:55

Run the following commands in guest machine/VM:

wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R vagrant:vagrant ~/.ssh

Then do vagrant halt. This will remove and regenerate your private keys.

(These steps assume you have already created or already have the ~/.ssh/ and ~/.ssh/authorized_keys directories under your home folder.)

查看更多
登录 后发表回答