gpt4 book ai didi

linux - 如何禁用 ssh-agent 转发

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:16:18 25 4
gpt4 key购买 nike

ssh-agent 转发可以通过 ssh -A ... 完成。

我发现的大多数引用资料都指出,本地计算机必须配置 ~/.ssh/config 以使用以下代码启用 AgentForwarding:

Host <trusted_ip>
ForwardAgent yes

Host *
ForwardAgent no

但是,使用此配置,当使用 ssh -A user@remote_not_trusted_ip 并运行 ssh-add - 隧道连接到远程机器时,我仍然能够看到我的本地机器 key 我.

根据上面的配置,我预计 ssh-agent 转发会失败,并且 ssh-add -l 不会列出本地计算机的 key 。

为什么机器 @remote_not_trusted_ip 能够访问 ssh-agent 转发的 key ,即使 ~/.ssh/config 文件声明如下?

Host *
ForwardAgent no

如何防止 ssh-agent 将 key 转发到未在 ~/.ssh/config 中明确定义的机器?

最佳答案

How can i prevent ssh-agent from forwarding keys to machines not explicitly defined in the ~/.ssh/config?

这是默认行为。如果您在 ~/.ssh/config 中不允许它,它将不会被转发。但是命令行参数具有更高的优先级,因此它会覆盖配置中定义的内容,如 ssh_config 的手册页中所述:

ssh(1) obtains configuration data from the following sources in the following order:

  1. command-line options
  2. user's configuration file (~/.ssh/config)
  3. system-wide configuration file (/etc/ssh/ssh_config)

如前所述,您只需向 ssh 提供正确的参数即可。

回到问题:

Why is the machine @remote_not_trusted_ip able to access the ssh-agent forwarded keys even though the ~/.ssh/config file states the following?

Host *
ForwardAgent no

因为命令行参数-A的优先级高于配置文件。

How can I prevent ssh-agent from forwarding keys to machines not explicitly defined in the ~/.ssh/config?

如果您不想转发您的ssh-agent,请不要使用-A 命令行选项。请改用 -a 命令行选项。

关于linux - 如何禁用 ssh-agent 转发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44335815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com