在 vagrant 来宾中使用来自主机的 ssh 私钥 [英] use ssh private key from host in vagrant guest
问题描述
我想在配置一个 vagrant box 的同时克隆一堆私有 git 存储库.根据这篇文章,这应该可以使用config.ssh.forward_agent = true
.但是,当尝试通过诸如 ssh -T git@github.com -o StrictHostKeyChecking=no
之类的内容连接到 github 时,它会失败并显示以下错误:
I want to clone a bunch of private git repositories while provisioning a vagrant box. According to this article this should be possible using config.ssh.forward_agent = true
. However, when trying to connect to github via something like ssh -T git@github.com -o StrictHostKeyChecking=no
it fails with the following error:
警告:将github.com,192.30.252.130"(RSA)永久添加到已知主机列表中.权限被拒绝(公钥).
Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts. Permission denied (publickey).
我将配置缩减为最简单的配置.你可以在这里找到它:https://gist.github.com/TomTasche/31f7c45fcffc2997d43a
I cut my configuration down to the simplest possible configuration. You can find it here: https://gist.github.com/TomTasche/31f7c45fcffc2997d43a
当我执行vagrant ssh"并再次尝试相同时,发生了类似的错误:
When I do "vagrant ssh" and try the same again, a similar error occurs:
克隆到私有存储库"...警告:已将 IP 地址192.30.252.130"的 RSA 主机密钥永久添加到已知主机列表中.权限被拒绝(公钥).致命:远端意外挂断
Cloning into 'private-repositories'... Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts. Permission denied (publickey). fatal: The remote end hung up unexpectedly
上面链接的配置可以在运行 Ubuntu 的主机上运行,但不能在 Mac 主机上运行,也不能在 Windows 主机上运行.我的目标是拥有一个适用于所有这三个主机的配置.
the configuration linked above does work on a host running Ubuntu, but does neither work on a Mac host, nor on a Windows host. My goal is to have a configuration that works on all these three hosts.
推荐答案
请检查您的主机系统是否启用了 ssh-agent 转发.例如,您可以将此块添加到您的 ~/.ssh/config
文件中:
Please check whether your host system has ssh-agent forwarding enabled. You can do so for example by adding this block to your ~/.ssh/config
file:
Host *
ForwardAgent yes
如果启用此功能,vagrant ssh
(以及vagrant provision
)应该能够将您的密钥转发到访客机器.
If this is enabled vagrant ssh
(and also vagrant provision
) should be able to forward your key to the guest machine.
您可能还想使用 ssh-add -l
检查您的 ssh-agent 是否知道您的 SSH 密钥.如果它在列表中并且您激活了代理转发,那么您应该会成功.否则,您可以通过运行 ssh-add
将密钥添加到 ssh-agent.
You also might want to check using ssh-add -l
whether your ssh-agent does know about your SSH-key. If it is in the list and you have agent-forwarding activated you should have a success. Otherwise you can add the key to your ssh-agent by running ssh-add <path to your key file>
.
这篇关于在 vagrant 来宾中使用来自主机的 ssh 私钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!