Vagrant 1.7在OSX上SSH认证失败 - 私钥未复制到虚拟机

4
首先,我知道这是一个重复的问题,但我花了20个小时来解决这个问题,因为其他问题的答案都对我无效。这是一个针对Mac OS X的特定问题和答案。虚拟机提供程序是VirtualBox 4.3和5.0。Vagrant版本为1.7.1和1.7.4。
SSH身份验证失败一直在发生。如果我等待或退出进程,我就可以使用默认密码"vagrant"无问题地进行"vagrant ssh"。但由于SSH失败,这意味着启动后脚本也没有执行。
vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'laravel/homestead'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: Setting the name of the VM: homestead
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 80 => 8000 (adapter 1)
    default: 443 => 44300 (adapter 1)
    default: 3306 => 33060 (adapter 1)
    default: 5432 => 54320 (adapter 1)
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> 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: Warning: Connection timeout. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
2个回答

1

Vagrant 1.7中默认配置为true:config.ssh.insert_key


Vagrant将自动插入一个密钥对用于SSH,在检测到时替换机器内部默认的不安全密钥。Vagrant SSH设置链接
当我执行vagrant up后,我使用vagrant ssh-config命令查看私钥路径为~/.vagrant.d/insecure_key,但该密钥未被复制到虚拟机内部。

问题出在我不知何故搞乱了我的OS X的SSH配置。当我运行命令ssh-add -l列出SSH代理中加载的密钥时,这一点变得显而易见。有两个不同的密钥具有相同的路径!然而,我无法确认这是否是问题的主要原因,因为问题已经持续了几天,在此期间我进行了几次重新启动。


我备份了 .ssh 文件夹,并逐一复制旧的配置行和文件。另外,我还删除了这个 不良建议提示,并添加了这一行到 ~/.ssh/config 中。
Host *
 ForwardAgent yes

这种做法强烈不建议Github采用:


警告:您可能会想使用通配符Host *,将此设置应用于所有SSH连接。这不是一个好主意,因为您将与每个SSH服务器共享本地SSH密钥。他们无法直接访问密钥,但在建立连接时,他们将能够像您一样使用它们。您应该只添加信任的服务器,并打算使用代理转发。


在执行这些步骤之前,我清空了~/.vagrant.d文件夹,以确保之前设置的全局配置不会影响。您也可以使用卸载脚本卸载Vagrant,然后重新安装。
重新启动。然后我创建了一个新的SSH密钥。
然后执行vagrant provision或者vagrant destroy && vagrant up命令。这就是我最终解决问题的方法!

1
我的解决方案是,在Vagrant显示“default: Warning: Authentication failure. Retrying...”时,从我的本地机器获取公共ssh密钥并将其放入vagrant中的~/.ssh/authorized_keys中。这使得vagrant能够无缝地ssh到框中,并在我的情况下继续进行配置。但我希望知道是什么导致了这个问题。(在发出vagrant up命令之前,我还删除了所有现有.vagrant和.vagrant.d文件的痕迹。)
cat ~/.ssh/id_rsa.pub
vagrant ssh
echo 'your-public key' >> ~/.ssh/authorized_keys (or paste it in by hand so you don't accidentally delete any existing keys)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接