kjo*_*kjo 11 git ssh github ssh-keys
我试图了解.ssh/config和.git/config下的配置如何相互作用.
这是情况:我有两个单独的github帐户,让我们称它们为GH0和GH1,我想与两个"无密码"进行交互,即在~/.ssh/id_rsa.GH0.pub
和中使用ssh密钥~/.ssh/id_rsa.GH1.pub
.目前这适用于GH0但不适用于GH1.(例如,push
命令GH1消亡ERROR: Repository not found.\nfatal: The remote end hung unexpectedly.
; ssh -T git@github.com
工作,但只是因为它连接GH0
.)
这意味着对于每个github帐户,我必须在〜/ .ssh/config中有相应的部分,指定要使用哪个ssh密钥文件.(例如,GH0的部分会有类似的东西IdentityFile ~/.ssh/id_rsa.GH0
等)
问题是:我还需要在这些部分中添加什么?进一步来说,
我必须把
Host
关键字作为参数放在~/.ssh/config
什么位置?
到目前为止我发现的信息对我来说毫无意义.在某些例子中,我看到类似的东西
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
Run Code Online (Sandbox Code Playgroud)
那个"ac2"在哪里.第二个前缀Host
来自???
我在哪里可以找到我的github帐户的相应内容?
我发现的一些信息导致人们猜测Host
关键字的参数实际上是任意的,暗示以下情况也会很好
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
Run Code Online (Sandbox Code Playgroud)
但如果是这样,这就提出了另一个问题:(或github)如何git
知道这两个部分中的哪一个用于任何给定的命令?
再次,我猜1这将在项目的.git/config
文件中指定,在某些[remote ...]
部分,但如何?
1 我必须求助于猜测,因为一方面,我无法找到解释.git/config中键值对的文档.我发现的最接近的是混帐配置手册页,但我无法找到的这个网页的任何文档url = ...
下的字段[remote ...]
部分.git-remote的手册页也没有关于此字段的文档.
请执行下列操作:
$ git remote add omgwtfbbq git@omgwtfbbq:user/repo.git
$ git pull omgwtfbbq master
Run Code Online (Sandbox Code Playgroud)
这将使用Host
您~/.ssh/config
在git主机中定义的别名,因此将使用您设置的IdentityFile.
归档时间: |
|
查看次数: |
4606 次 |
最近记录: |