从SSH代理使用特定的转发密钥?

比方说,我有一个关键Github,以及其他键。 我在我的家庭计算机上添加了很多密钥给我的ssh代理( ssh-add -L返回很多行)。在我的.ssh/config我已经设置了哪个密钥与哪个主机一起使用,例如

 ssh -T -vvv [email protected] 2>&1 | grep Offering 

 debug1: Offering RSA public key: /Users/doxna/.ssh/id_rsa.github 

如预期的那样,只提供一个密钥。 但是,然后使用ForwardAgent yes对某个主机B进行ssh,然后重复相同的命令

 debug1: Offering RSA public key: /Users/doxna/.ssh/id_rsa.linode2 debug1: Offering RSA public key: /Users/doxna/.ssh/id_rsa.helium debug1: Offering RSA public key: /Users/doxna/.ssh/id_rsa.github 

这意味着它尝试我所有的密钥。 这是有问题的,因为在服务器返回Too many authentication failures之前,只能使用有限数量的密钥。 所以我试着在主机B上编辑.ssh/config来包含

 Host github.com IdentityFile /Users/doxna/.ssh/id_rsa.github IdentitiesOnly yes 

但是我没有得到重要的产品,而是

 debug2: key: /Users/doxna/.ssh/id_rsa.github ((nil)) 

我想这意味着没有find密钥(?)毕竟,密钥位于我的家庭计算机A,而不是主机B,所以问题是如何在主机B参考它? 希望我能够解释这个问题。

你有正确的想法。 你唯一缺less的是由IdentityFile指向的文件必须存在。 它不需要包含一个私钥,只需要公钥就足够了。

在主机B上,您可以通过键入ssh-add -L | grep /Users/doxna/.ssh/id_rsa.github > ~/.ssh/id_rsa.github.pub从代理中提取公钥 ssh-add -L | grep /Users/doxna/.ssh/id_rsa.github > ~/.ssh/id_rsa.github.pub ,然后从~/.ssh/config指向该文件

尼斯回答@Kasperd,但也请注意,如果主机B受到威胁,或者如果你不信任所有那些拥有root权限的人,那么只要你login,你仍然暴露你的所有密钥滥用在那个主机上。

所以更好的方法可能是只转发你需要的密钥。 也许尝试在debian / Ubuntu存储库,或从github的 ssh-agent-filter

编辑:我已经解决了ssh-ident而不是ssh-agent-filterselect转发密钥,虽然它不像人们可能希望的那样stream畅。