macos – Vagrant 1.7 OSX上的SSH身份验证失败 – 私钥未复制到VM

首先,我知道这是一个重复的问题,但我与这个问题争斗了大约20个小时,因为其他问题的答案都没有对我有用.这是Mac OS X的具体问题和答案.虚拟提供程序是VirtualBox 4.3和5.0. Vagrant版本1.7.1和1.7.4

此SSH身份验证失败仍在继续.如果我等待或退出过程,我可以毫无问题地“流浪ssh”,使用默认密码“vagrant”.但是因为这个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.

最佳答案 Vagrant 1.7将此默认配置设置为true:config.ssh.insert_key

Vagrant将自动插入用于SSH的密钥对,如果检测到,则替换机器内部的默认Vagrant不安全密钥. link to Vagrant SSH settings

在流浪汉之后我做了vagrant ssh-config我可以看到私钥路径是〜/ .vagrant.d / insecure_key – 但是该密钥也没有复制到VM内部.

问题在于我以某种方式弄乱了我的OS X的SSH配置.当我在SSH代理中运行命令ssh-add -l列出已加载的密钥时,这一点很明显.有两个不同的键具有相同的路径!但是我不能确认这是问题的主要原因,因为它持续了几天,在此期间我做了一些重新启动.

我备份了.ssh文件夹并逐个复制旧的配置行和文件.我做的另一件事是删除这个ill-advised tip以在〜/ .ssh / config中添加这一行

Host *
 ForwardAgent yes

这种做法是strongly recommended against by Github

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

在执行这些步骤之前,我清空〜/ .vagrant.d文件夹以确保我之前没有设置全局配置.您也可以使用卸载脚本卸载Vagrant,然后重新安装.

重新启动.然后我创建了一个新的SSH密钥.

然后流浪汉提供或流浪汉摧毁&&流浪汉.这就是我终于解决了这个问题的方法!

点赞