大网数据广告活动
服务器运维问答

Use a specific forwarded key from SSH-agent?

· 52CE 我爱测

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…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-05-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。