问题原文
原帖链接 · danmichaelo · CC BY-SA 3.0
Let's say I have a key for Github, along with other keys. I've added lots of keys to my ssh agent (ssh-add -L returns lots of lines) at my home computer A. In my .ssh/config I have set up which key to use with which host, so e.g.
ssh -T -vvv [email omitted] 2>&1 | grep Offering
gives
debug1: Offering RSA public key: /Users/doxna/.ssh/id_rsa.github
Only one key is offered, as expected. But then ssh-ing to some host B with ForwardAgent yes and repeating the same command, I get
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
meaning it tries all my keys. This is problematic since only a limited number of keys can be tried before servers return Too many authentication failures. So I tried editing .ssh/config on host B to include
Host github.com
IdentityFile /Users/doxna/.ssh/id_rsa.github
IdentitiesOnly yes
but then I get no key offerings, but rather
debug2: key: /Users/doxna/.ssh/id_rsa.github ((nil))
which I guess means that the key was not found(?) And after all, the key is located at my home computer A, not host B, so the question is how to refer to it at host B? Hope I managed to explain the question.
社区高分解答
原帖链接 · mc0e · CC BY-SA 4.0
Nice answer from @Kasperd, but note also that if Host B is compromised, or if you don't trust all those with root privileges there, then you're still exposing all of your keys to abuse for as long as you're logged in on that host.
So a better approach might be to only forward access to the keys you need. Maybe try ssh-agent-filter which is in debian / Ubuntu repositories, or from github.
EDIT: I've settled on ssh-ident rather than ssh-agent-filter for forwarding keys selectively, though it's not as smooth an experience as one might hope for.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
