推送到多个github帐户

时间:2016-06-27 13:32:42

标签: git github ssh

我目前需要推送到多个github帐户。 为简单起见,我们需要两个帐户。

https://github.com/user1/repositoryName
https://github.com/user2/repositoryName

我曾经使用过user1,这是我的个人帐户。 User2是我的工作帐户。

现在,当我把git推送到我的工作帐户时:

remote: Permission to user2/repositoryName.git denied to user1.
fatal: unable to access 'https://github.com/nitte93/reactogram.git/': The requested URL returned error: 403

经过一番浏览后,我发现我需要为每个帐户设置一个单独的SSH密钥。

所以我做了。

个人

cd .ssh 
ssh-keygen -t rsa -b 4096 -C "user1@example.com"
 //gave it a name of personal
chmod 400 ~/.ssh/personal
ssh-add ~/.ssh/personal

Added it to github>settings>ssh.

工作

cd .ssh 
ssh-keygen -t rsa -b 4096 -C "user1@work.com"
 //gave it a name of work
chmod 400 ~/.ssh/work
ssh-add ~/.ssh/work

Added it to github>settings>ssh.


ls .ssh
Had both the files.
Namely: peronal personal.pub work work.pub defaultones

接下来我做了:

   vi config

将其更新为

Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/personal

Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/personal

变种:ssh -T git@github.com 得到消息:

Hi user1! You've successfully authenticated, but GitHub does not
provide shell access.

事情是我的工作链接形式为:https://github.com/work而不是 work.github.com 但只有user2(工作)才能访问它。 User2(个人)没有。

接下来,当我试图推动我的工作回购。我一直得到同样的错误。

remote: Permission to user1/repositoryName.git denied to user2.
fatal: unable to access 'https://github.com/nitte93/reactogram.git/': The requested

我知道还有其他一些问题涉及同一问题。但我相信我正确地遵循了它们。我不确定我是否错过任何一步。 如果我错过了任何步骤,请指导我。 我希望能够推动这两个回购。

1 个答案:

答案 0 :(得分:2)

如果您使用SSH作为GitHub的远程用户,那么您不应该使用使用https://的远程URL。你的遥控器应该是这样的:

git@github.com:user1/repository.git