Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.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
使用SSH处理多个github帐户失败_Git_Github_Ssh_Https_Account - Fatal编程技术网

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

使用SSH处理多个github帐户失败,git,github,ssh,https,account,Git,Github,Ssh,Https,Account,我在github上有一个个人帐户和一个工作帐户。我在~/.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: Re

我在github上有一个个人帐户和一个工作帐户。我在
~/.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
我得到了
你好,伊利亚
这是个人用户名

这是工作帐户的
配置

[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

您是否完成了
ssh添加~/.ssh/work rsa key

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

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

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

现在,
git pull
应该可以工作了。

在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时,它将尝试在身份验证代理中找到的每个身份。这就是为什么这种方法不被推荐的原因