Authentication failure when using vagrant up with

2019-08-07 06:36发布

问题:

I'm new to Vagrant, so I'm taking baby steps to make sure that I understand the process. I want to ensure that I can create a custom package before I start doing any serious development in the virtual machine. For now, I have simply used the official ubuntu/xenial64 Vagrant box, and provisioned it so that nginx is installed. You can find my step-by-step guide to this here.

My customized box works fine. I use vagrant package --output nginx.box and then vagrant box add nginx nginx.box to add my custom box to my Vagrant Install. It is when I try creating a new box from the custom package that my problem appears.

I create a new directory and use vagrant init nginx to create a clone of my custom box, but when I use vagrant up, Vagrant fails to authenticate:

  ==> 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: Warning: Connection reset. Retrying...
  default: Warning: Remote connection disconnect. Retrying...
  default: Warning: Connection reset. Retrying...
  default: Warning: Remote connection disconnect. Retrying...
  default: Warning: Connection reset. Retrying...
  default: Warning: Remote connection disconnect. Retrying...
  default: Warning: Connection reset. Retrying...
  default: Warning: Remote connection disconnect. Retrying...
  default: Warning: Connection reset. Retrying...
  default: Warning: Remote connection disconnect. Retrying...
  default: Warning: Authentication failure. Retrying...
  default: Warning: Authentication failure. Retrying...
  default: Warning: Authentication failure. Retrying...

If I connect to the VM through VirtualBox Manager, I'm asked to authenticate, and using the login and password "vagrant" fails.

I've looked at this question and this other question which describe similar symptoms, but I haven't yet found a solution to my problem in the answers. When I run vagrant up --debug, I get this output repeating after the VM has spun up. The key passage seems to be:

 DEBUG ssh: == Net-SSH connection debug-level log END ==
 INFO ssh: SSH not ready: #<Vagrant::Errors::SSHAuthenticationFailed:
 SSH authentication failed! This is typically caused by the public/private
keypair for the SSH user not being properly set on the guest VM. Please
verify that the guest VM is setup with the proper public key, and that
the private key path for Vagrant is setup properly as well.>

What do I need to do before I package my custom box so that any developer will be able to use it without performing any voodoo on the public and private keys?

回答1:

This box is password authenticated, when you install the box, you can check its Vagrantfile for the password (on my Mac, I will see the file at ~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170116.1.0/virtualbox)

config.ssh.username = "ubuntu"
config.ssh.password = "95bf98670a543bcd7bdd576c"

The easiest would probably to repackage this same file when you build your own box (see https://www.vagrantup.com/docs/cli/package.html#vagrantfile-file), so on your step

Repackage as a new Vagrant Box:

vagrant package --output nginx.box

I would run

vagrant package --vagrantfile <path_to_original_box_vagrantfile> --output nginx.box