将 vagrant up 与准系统自定义包一起使用时身份验证失败

Authentication failure when using vagrant up with a barebones custom package

我是 Vagrant 的新手,所以我正在逐步了解这个过程。我想确保在开始在虚拟机中进行任何认真的开发之前,我可以创建一个自定义包。目前,我只是简单地使用了官方的 ubuntu/xenial64 Vagrant box, and provisioned it so that nginx is installed. You can find my step-by-step guide to this here.

我定制的盒子很好用。我使用 vagrant package --output nginx.box 然后 vagrant box add nginx nginx.box 将我的自定义框添加到我的 Vagrant 安装中。当我尝试从自定义包创建一个新盒子时,我的问题出现了。

我创建了一个新目录并使用 vagrant init nginx 创建了自定义框的克隆,但是当我使用 vagrant up 时,Vagrant 无法 验证:

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

如果我通过 VirtualBox Manager 连接到 VM,系统会要求我进行身份验证,并且使用登录名和密码 "vagrant" 失败。

我看过 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 在 VM 启动后重复。关键段落似乎是:

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

在打包我的自定义盒子之前我需要做什么,以便任何开发人员都可以使用它而无需对 public 和私钥执行任何巫术?

这个盒子是密码验证的,当你安装盒子时,你可以检查它的 Vagrantfile 来获取密码(在我的 Mac,我会在 ~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170116.1.0/virtualbox 看到文件)

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

最简单的方法可能是在构建自己的盒子时重新打包同一个文件(请参阅 https://www.vagrantup.com/docs/cli/package.html#vagrantfile-file),所以在您的步骤中

Repackage as a new Vagrant Box:

vagrant package --output nginx.box

我会运行

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