【问题标题】:How to prevent git from automatically adding host keys?如何防止git自动添加主机密钥?
【发布时间】:2020-02-16 18:12:06
【问题描述】:

假设我添加了一个新的遥控器,我想通过 ssh 连接到该遥控器。我忘记将服务器的主机密钥添加到我的~/.ssh/known_hosts 文件并无论如何都要连接。令我惊讶的是,我收到以下警告

警告:将 IP 地址“xxxx:xxx:xxx:xxxx::xxx”的 RSA 主机密钥永久添加到已知主机列表中

我不希望 git 在这种情况下自动添加主机密钥。如果有人问我或者没有添加主机密钥,我会更高兴。

我尝试添加

[core]
    sshCommand = ssh -o StrictHostKeyChecking=ask

致我的~/.gitconfig。我的~/.ssh/config 中也有StrictHostKeyChecking ask。这两个设置都被忽略。我的 git 版本是 2.17.1。

问题:

  1. 如何防止git自动添加主机密钥?
  2. 为什么我的 StrictHostKeyChecking 设置被忽略了?

【问题讨论】:

  • 我无法通过 MacPorts 安装的 Git 2.25.0 复制此行为。我得到了正常的 ssh 询问行为。 git fetch originThe authenticity of host '...' can't be established. RSA key fingerprint is SHA256:blahblahblah. Are you sure you want to continue connecting (yes/no)?
  • 检查git config -l --show-origin是否有什么奇怪的地方。
  • @Schwern core.sshcommand=ssh -o StrictHostKeyChecking=ask 出现在那里并且没有其他冲突的命令。我会检查更新版本的 git。
  • @Schwern 刚刚在 arch linux 上使用 git 版本 2.25.0 进行了测试。无法使用相同的 repo 重现错误。似乎它已更改/修复。

标签: git


【解决方案1】:

man ssh_config:

在所有情况下都会自动验证已知主机的主机密钥。

【讨论】:

  • 我理解这句话是指known_hosts 文件中的主机密钥。这些将被自动验证(无需询问),这对我来说很好。对于 已知的主机密钥,我希望 git 询问如何进行。
猜你喜欢
  • 1970-01-01
  • 2012-04-13
  • 2015-06-13
  • 2017-08-20
  • 2018-05-15
  • 1970-01-01
  • 1970-01-01
  • 2021-07-11
  • 1970-01-01
相关资源
最近更新 更多