【问题标题】:Vagrant "Authentication failure" during up, but "vagrant ssh" can get in just fineVagrant“身份验证失败”在启动期间,但“vagrant ssh”可以正常进入
【发布时间】:2015-04-01 18:36:19
【问题描述】:

我被难住了。我正在尝试在 Windows 8.1 上运行 vagrant/virtualbox/coreos 集群来开发在云中运行的集群。我已经在四台机器上尝试过这个(都是带有最新更新的 Windows 8.1,并且都带有最新的 VirtualBox、Vagrant、Git 和相同的 Vagrant 配置。我正在从所有 4 个系统的 repo 中检查 Vagrant 配置,所以我相信每个配置都是相同的。我得到 2 次成功和 2 次失败。

两台机器成功如下:

Bringing machine 'core-01' up with 'virtualbox' provider...
==> core-01: Checking if box 'coreos-stable' is up to date...
(snip)
    core-01: SSH address: 127.0.0.1:2222
    core-01: SSH username: core
    core-01: SSH auth method: private key
    core-01: Warning: Connection timeout. Retrying...
==> core-01: Machine booted and ready!
==> core-01: Setting hostname...
==> core-01: Configuring and enabling network interfaces...

vagrant ssh 和 vagrant halt 在这两个系统上都可以正常工作。

另外两台 Windows 机器失败如下:

Bringing machine 'core-01' up with 'virtualbox' provider...
==> core-01: Importing base box 'coreos-stable'...
==> core-01: Matching MAC address for NAT networking...
==> core-01: Checking if box 'coreos-stable' is up to date...
==> core-01: Setting the name of the VM: coreos-vm-cluster_core-01_1422899531630_88904
==> core-01: Clearing any previously set network interfaces...
==> core-01: Preparing network interfaces based on configuration...
    core-01: Adapter 1: nat
    core-01: Adapter 2: hostonly
==> core-01: Forwarding ports...
    core-01: 22 => 2222 (adapter 1)
==> core-01: Running 'pre-boot' VM customizations...
==> core-01: Booting VM...
==> core-01: Waiting for machine to boot. This may take a few minutes...
    core-01: SSH address: 127.0.0.1:2222
    core-01: SSH username: core
    core-01: SSH auth method: private key
    core-01: Warning: Connection timeout. Retrying...
    core-01: Warning: Authentication failure. Retrying...
    core-01: Warning: Authentication failure. Retrying...
    core-01: Warning: Authentication failure. Retrying...
    core-01: Warning: Authentication failure. Retrying...
    core-01: Warning: Authentication failure. Retrying...
    core-01: Warning: Authentication failure. Retrying...

注意工作系统和非工作系统如何经历一次超时连接,但成功的系统确实连接并完成启动 VM,而不成功的系统只是陷入身份验证重试循环强>.

在身份验证失败后,如果我让它超时或者即使我 ctrl+C,我可以运行“vagrant ssh core-01”并直接进入

CoreOS (stable)
core@localhost ~ $

'vagrant halt' 也无法在这些系统上建立 ssh 连接:

==> core-01: Attempting graceful shutdown of VM...
    core-01: Guest communication could not be established! This is usually because
    core-01: SSH is not running, the authentication information was changed,
    core-01: or some other networking issue. Vagrant will force halt, if
    core-01: capable.
==> core-01: Forcing shutdown of VM...

我可以成功地使用 putty 或其他 ssh 客户端访问使用 insecure_private_key 进行身份验证的 VM,所以我假设 VM 本身具有正确的配置,问题在于 Vagrant 的调用能力ssh 进入。如果 "Vagrant up" 不能 ssh 进入,它无法完成 VM 的启动配置,所以我想主要出于这个原因解决这个问题。

这是让我与其他 ssh 客户端一起使用的 ssh 配置,我相信 Vagrant 应该使用它:

Host: 127.0.0.1
Port: 2222
Username: core
Private key: C:/Users/Mike/.vagrant.d/insecure_private_key

我还为虚拟机启用了 GUI,控制台没有显示任何错误;它一直到登录提示都很好(这也与我可以 ssh 进入并以其他方式使用 VM 的事实一致)。

我相信(但不知道如何验证)Vagrant 正在 C:\Program Files (x86)\Git\bin 中调用 openssh 客户端

所有版本都在运行 Vagrant 1.7.2 和 git 1.9.5。红宝石 2.0.0p353。

我的 %PATH% 大约有 500 个字符长。我确信 Vagrant 正在寻找某种 ssh 客户端,因为至少有一个或两个超时,然后是身份验证失败。

提前感谢您的任何想法!

更新:深埋在“vagrant up --debug”的输出中的是这个小宝石:

D, [2015-02-02T23:11:10.755468 #3920] DEBUG --
   net.ssh.authentication.session[14661cc]: trying publickey
E, [2015-02-02T23:11:10.756472 #3920] ERROR --
   net.ssh.authentication.key_manager[1473e1c]:
   could not load public key file
   `C:/Users/Mike/.vagrant.d/insecure_private_key': 
   Net::SSH::Exception (public key at
   C:/Users/Mike/.vagrant.d/insecure_private_key.pub is not valid)

最后的“insecure_private_key.pub 无效”似乎是一个可靠的线索。

我尝试修改该文件以确保它只有 LF 用于行尾以及 CRLF,这没有任何区别。视觉上看起来不错。它也与在其他系统之一上运行的文件 100% 逐字节相同。为什么会无效?我已经验证当前用户对文件具有完全控制权限,并且还尝试以管理员身份 vagrant up。行为没有变化。 :(

【问题讨论】:

  • 如需帮助解决问题,您可以enable GUI mode for the VM。有时这会显示来宾操作系统卡在登录或其他步骤中。
  • 另外,如果您认为 Vagrant 使用的 SSH 客户端可能存在问题,请参阅此 SO 线程中的一些讨论和想法:SSH to Vagrant box in Windows?
  • 感谢 BrianC。我试过了,没有看到控制台上出现任何错误。我在上面进行了编辑以反映我采取的这个额外的调试步骤。请注意,VM 可以正常启动(我这么说是因为我可以通过 ssh 进入它),但 Vagrant 无法通过 ssh 进入以完成其启动脚本。
  • @BrianC,是的,这个问题是 100% 一致的,即它在 2 个系统上 100% 的时间有效,而在其他 2 个系统上 100% 的时间失败。我已经完成了无数次流浪破坏,结果保持一致。然而,“vagrant up --debug” 是一个很好的提示!在“Buried deep in the output...”之后查看上面的新编辑。
  • @Rob,根据安全属性,当前用户可以完全控制该文件。我还以管理员身份尝试了 vagrant up --debug 并得到相同的“insecure_private_key.pub is not valid”消息。 :( 检查权限是个好主意;谢谢。

标签: windows ssh vagrant coreos


【解决方案1】:

.pub 文件是由 Puttygen 创建的吗(可能是在创建 Putty 格式的私钥时)?我这样做了,它阻止了 vagrant 连接到盒子,但我可以使用 Putty 和 Puttygen 生成的 .ppk 文件进行连接。

更改 Putty 公钥的扩展名对我有用,大概是因为 Vagrant 不再尝试使用它。

【讨论】:

  • 好主意,所以我决定归档到另一个文件夹 insecure_private_key* 并仅使用 ssh-keygen 从头开始​​重新创建。仍然没有运气,并且与以前相同的错误消息(insecure_private_key.pub 无效)。然后我将 insecure_private_key 移动到本地目录并设置 config.ssh.private_key_path = './insecure_private_key' now 看起来它是一个简单的密钥不匹配。我现在没有时间完全调试,但似乎有进步!
【解决方案2】:

当我创建 insecure_private_key 文件的 PPK 文件时,我也——出于习惯——创建了一个 .pub 版本。这似乎导致了问题。和 Jon 一样,当我删除 insecure_private_key.pub 文件时,vagrant up 能够一直运行。

如果您使用 puttygen 创建了 insecure_private_key.pub 文件并遇到此问题,我建议您将其删除。 vagrant 不需要它,它只会妨碍它。

【讨论】:

    【解决方案3】:

    删除
    C:/Users/Mike/.vagrant.d/insecure_private_key

    下次 vagrant 重启时会再次创建(这次应该是正确的)

    【讨论】:

    • 我使用homestead,就我而言,我必须将~/.ssh/id_rsa复制到homestead_folder/.vagrant/machines/{my-machine-name}/virtualbox/private_key
    猜你喜欢
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 2015-11-15
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    相关资源
    最近更新 更多