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

时间:2014-05-27 08:31:48

标签: git github ssh https account

我在github上有个人和工作帐户。我有两个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

当我使用个人帐户时,一切都很好但是当我尝试拉/推到工作帐户时我得到了

$ 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.

当然我确认地址是正确的。

当我ssh -T git@github.com时,我得到Hi ilya! ...这是个人用户名。

这是工作帐户的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

2 个答案:

答案 0 :(得分:0)

你做过ssh-add ~/.ssh/work-rsa-key吗?

通过执行ssh-add -l验证是否列出了所有密钥。

然后,您可以执行以下操作:

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

现在,git pull应该有效。

答案 1 :(得分:0)

将以下行添加到“ SSH配置”部分:

IdentitiesOnly yes

例如:

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

或者,您可能想通过运行将私钥身份添加到身份验证代理中

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

执行git pull时,它将尝试在身份验证代理中找到的每个身份。这就是为什么不推荐这种方法的原因。