Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我怎样才能抑制git@example.com优先于git@tweak.example.com?_Git_Ssh - Fatal编程技术网

我怎样才能抑制git@example.com优先于git@tweak.example.com?

我怎样才能抑制git@example.com优先于git@tweak.example.com?,git,ssh,Git,Ssh,我在基于Git的forge[1]上有多个帐户,我想通过SSH(而不是HTTPS)签出和管理回购。我目前的做法是: 为每个帐户创建不同的密钥文件 在我的SSH配置中,为每个帐户创建一个假主机 将每个密钥文件作为标识文件分配给匹配的假主机 使用git@fake.example.com而不是git@example.com (这遵循给出的建议和。) 我现在可以ssh-T了git@id1.example.com或ssh-Tgit@id2.example.com并以类似方式执行Git任务 但是,我仍然可

我在基于Git的forge[1]上有多个帐户,我想通过SSH(而不是HTTPS)签出和管理回购。我目前的做法是:

  • 为每个帐户创建不同的密钥文件
  • 在我的SSH配置中,为每个帐户创建一个假主机
  • 将每个密钥文件作为标识文件分配给匹配的假主机
  • 使用git@fake.example.com而不是git@example.com
(这遵循给出的建议和。)

我现在可以
ssh-T了git@id1.example.com
ssh-Tgit@id2.example.com
并以类似方式执行Git任务

但是,我仍然可以使用
git@example.com
,它似乎与我的默认id\u rsa密钥关联。我试图按如下方式覆盖此选项:

Host example.com
  Hostname example.com
  User git
  IdentityFile ~/.ssh/none
…其中
~/.ssh/none
是包含伪文本的文本文件。但是,ssh尝试仍然成功,与我的默认id_rsa密钥相关

如何覆盖此情况,使尝试失败,迫使我显式使用某个特定于帐户的主机


[1] 到目前为止,我知道这适用于GitHub和BitBucket,但我认为这里有一个通用原则。

最简单的方法是删除
id\u rsa.key
文件,以防止SSH找到“默认”身份验证密钥

小心备份该文件!当然,保留已配置的
IdentityFile
键。只是在
~/.ssh
中没有
id\u rsa.key

Host example.com
  Hostname example.com
  User git
  IdentityFile ~/.ssh/none