简体   繁体   English

使用SSH处理多个github帐户失败

[英]Working with multiple github accounts with SSH fails

I have a personal and a work accounts on github. 我在github上有个人账户和工作账户。 I have SSH keys for both and this config file in the ~/.ssh 我在~/.ssh都有这两个config文件的SSH密钥

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

Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/work-rsa-key

When I work with the personal account all is fine but when I try to pull/push to the work account I get 当我使用个人帐户时,一切都很好,但是当我尝试使用/推入工作帐户时,我得到了

$ git pull
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Of course I verified the address is correct. 我当然确认地址正确。

When I do ssh -T git@github.com I get Hi ilya! ... 当我执行ssh -T git@github.com我会收到Hi ilya! ... Hi ilya! ... which is the personal user name. Hi ilya! ...这是个人用户名。

This is the config for the work account: 这是工作帐户的config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = false
[branch "dev"]
[remote "origin"]
    url = git@github-work:work/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "dev"]
    remote = origin
    merge = refs/heads/dev
[branch "unify"]
    remote = origin
    merge = refs/heads/unify
[user]
    name = ilya-work
    email = ilya@work.com

Have you done ssh-add ~/.ssh/work-rsa-key ? 您完成ssh-add ~/.ssh/work-rsa-key吗?

Verifiy that all your keys are listed by doing ssh-add -l . 通过执行ssh-add -l是否列出了所有密钥。

Then, you can do the following: 然后,您可以执行以下操作:

git config user.name "ilya-work"
git config user.email "ilya@work.com"

Now, git pull should work. 现在, git pull应该可以了。

Add the following line to your SSH config section: 将以下行添加到“ SSH配置”部分:

IdentitiesOnly yes

For example: 例如:

Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/work-rsa-key
  IdentitiesOnly yes

Alternatively, you might want to add your private key identitiy to the authentication agent, by running 或者,您可能需要通过运行以下命令将您的私钥身份添加到身份验证代理:

$ ssh-add ~/.ssh/work-rsa-key

When executing git pull , it will try every identities found in your authentication agent. 当执行git pull ,它将尝试在身份验证代理中找到的所有身份。 That's why this method is not (much) recommended. 这就是为什么不推荐这种方法的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM