两个不同的Github帐户在同一个RStudio中

时间:2017-10-11 02:17:39

标签: github rstudio ssh-keys

我可以为不同的GitHub帐户管理多个SSH密钥,这样我就可以访问多个帐户和项目,每个帐户和项目都有不同的凭据。但是,我可以在同一个RStudio上的两个不同的github帐户(推拉)上工作两个不同的项目吗?我在网上搜索但找不到答案。我的文件夹中有相关的SSH密钥。但是,我无法在RStudio的全局选项中更改SSH RSA密钥,因为它始终放置文件~/.ssh/id_rsa。但我还有另一个密钥用于我的另一个Github帐户~/.ssh/id_rsa_SECOND。我将不胜感激任何帮助!谢谢!

编辑: 我的配置文件有,

Host me.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile Clone  ~/.ssh/id_rsa

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

告诉我使用me.github.com而不是github.com作为第一个Github帐户中存储库的主机(带有身份〜/ .ssh / id_rsa)并使用github.com作为第二个Github帐户中的存储库(带有身份〜/ .ssh / id_rsa_SECOND)。但是,当我在我的个人帐户中克隆存储库时,使用git@ **me**.github.com:username/hugo-academic.git不起作用。

2 个答案:

答案 0 :(得分:1)

这是一个老问题,但如果其他人遇到这个问题,解决方案(对我来说)是在 ~/.ssh/config 的每个块中包含 github 用户名。如:

# USERNAME-1 at github:                                                                                                                                                          
Host github.com-1
  HostName github.com
  User USERNAME-1
  IdentityFile ~/.ssh/id_rsa_1
  IdentitiesOnly yes
# USERNAME-2 at github:                                                                                                                                                           
Host github.com-2
  HostName github.com
  User USERNAME-2
  IdentityFile ~/.ssh/id_rsa_2
  IdentitiesOnly yes

在 github URL 中,根据需要将“github.com”更改为“github.com-1”或“github.com-2”,例如,您将使用以下命令进行克隆:

git clone git@github.com-1:USERNAME-1/foo.git

代替:

git clone git@github.com:USERNAME-1/foo.git

答案 1 :(得分:0)

对于每个answer文档,请检查useHttpPath设置(您的凭据。名称空间可能会有所不同。在我的情况下,它是github.com):

git config --global credential.github.com.useHttpPath true