【发布时间】:2016-06-27 13:32:42
【问题描述】:
我目前需要推送到多个 github 帐户。 为简单起见,让我们考虑两个帐户。
https://github.com/user1/repositoryName
https://github.com/user2/repositoryName
我曾经使用 user1,这是我的个人帐户。 User2 是我的工作帐号。
现在,当我执行 git push 到我的工作帐户时:
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 而不是 工作.github.com 但只有 user2(work) 可以访问它。用户 2(个人)没有。
接下来当我尝试推送到我的工作仓库时。我不断收到同样的错误。
remote: Permission to user1/repositoryName.git denied to user2.
fatal: unable to access 'https://github.com/nitte93/reactogram.git/': The requested
我知道还有其他几个问题涉及同一问题。但我相信我正确地跟随了他们。我不确定我是否缺少任何步骤。 如果我缺少任何步骤,请指导我。 我希望能够推送到两个存储库。
【问题讨论】:
-
如果你使用 SSH 作为 Github 的远程,那么你的远程 URI 应该是
git@github.com:user1/repo.git。