多个github帐户:.ssh/config中Host的值是什么? [英] Multiple github accounts: what values for Host in .ssh/config?

查看:292
本文介绍了多个github帐户:.ssh/config中Host的值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解.ssh/config和.git/config下的配置如何交互.

I'm trying to understand how the configurations under .ssh/config and .git/config interact.

这里是这种情况:我有两个单独的github帐户,我们将它们称为GH0和GH1,并且我想同时使用无密码"功能,即在~/.ssh/id_rsa.GH0.pub~/.ssh/id_rsa.GH1.pub中使用ssh键进行交互.目前,它适用于GH0,但不适用于GH1. (例如,向GH1发送的push命令与ERROR: Repository not found.\nfatal: The remote end hung unexpectedly.一起消失; ssh -T git@github.com有效,但这仅是因为它连接了GH0.)

Here's the situation: I have two separate github accounts, let's call them GH0 and GH1, and I want to interact with both "passwordlessly", i.e., using ssh keys in ~/.ssh/id_rsa.GH0.pub and ~/.ssh/id_rsa.GH1.pub. At the moment this works for GH0 but not for GH1. (E.g., push commands to GH1 die with ERROR: Repository not found.\nfatal: The remote end hung unexpectedly.; ssh -T git@github.com works, but only because it connects GH0.)

这意味着对于每个github帐户,我都必须在〜/.ssh/config中有相应的部分,并指定要使用的ssh密钥文件. (例如,GH0的部分将显示IdentityFile ~/.ssh/id_rsa.GH0等)

This means that for each of these github accounts I have to have a corresponding section in ~/.ssh/config, specifying which ssh key file to use for it. (E.g., the section for GH0 will have something like IdentityFile ~/.ssh/id_rsa.GH0, etc.)

问题是:在这些部分中我还必须添加什么?更具体地说,

The question is: what else do I have to put in each of these sections? More specifically,

我必须在~/.ssh/config中将什么作为Host关键字的参数?

what do I have to put as the argument to the Host keyword in ~/.ssh/config?

到目前为止,我发现的信息对我来说毫无意义.在某些示例中,我看到类似

The information that I've found so far on this makes no sense to me. In some examples, I see stuff like

Host github.com
    Hostname github.com
    User git
    IdentityFile ~/.ssh/id_rsa

Host ac2.github.com
    Hostname github.com
    User git
    IdentityFile ~/.ssh/id_rsa_ac2

"ac2"在哪里.第二个Host中的前缀来自???

Where does that "ac2." prefix in the second Host come from???

在哪里可以找到我的github帐户对应的帐户?

Where do I find the corresponding ones for my github accounts?

我发现的一些信息使人们猜测Host关键字的参数实际上是任意的,这意味着下面的内容也可以

Some of the info I've found lead one to guess that arguments to the Host keyword are in fact arbitrary, implying that the following would be fine too

Host omgwtfbbq
    Hostname github.com
    User git
    IdentityFile ~/.ssh/GH0

Host 4.8.15.16.23.42
    Hostname github.com
    User git
    IdentityFile ~/.ssh/GH1

但是,如果是这样,这又引发了另一个问题: git(或github)如何知道对任何给定命令使用这两部分中的哪一部分?

But if so, this raises yet another question: How does git (or github) know which of these two sections to use for any given command?

再次,我猜测 1 ,这将在项目的.git/config文件中的[remote ...]部分下指定,但是如何?

Again, I guess1 that this would be specified in the project's .git/config file, under some [remote ...] section, but how?

1 我必须求助于猜测,因为,一方面,我无法在.git/config中找到解释键值对的文档.我找到的最接近的是git-config的手册页,但是我在此页面的[remote ...]部分下的url = ...字段中找不到任何文档. git-remote的手册页也没有关于此字段的文档.

1I must resort to guessing because, for one thing, I have not been able to find documentation for the interpretation of the key-value pairs in .git/config. The closest I've found is the man page for git-config, but I can't find any documentation in this page for the url = ... field under a [remote ...] section. The man page for git-remote, too, has no documentation about this field.

推荐答案

执行以下操作:

$ git remote add omgwtfbbq git@omgwtfbbq:user/repo.git
$ git pull omgwtfbbq master

这将使用您在~/.ssh/config中定义的Host别名作为git主机,因此将使用您已设置的IdentityFile.

This will use the Host alias you've defined in your ~/.ssh/config as the git host, and thus will use the IdentityFile you've setup.

这篇关于多个github帐户:.ssh/config中Host的值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆