Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two different Github accounts in the same RStudio

I can manage multiple SSH keys for different GitHub accounts so that I can access multiple accounts and projects, each with different credentials. However, is it possible for me to work on two different projects on two different github accounts (push and pull) in the same RStudio? I searched online but could not find an answer. I have related SSH keys in my folder. However, I cannot change SSH RSA key in Global Options of RStudio since it always puts the file ~/.ssh/id_rsa. But I also have another key for my another Github account ~/.ssh/id_rsa_SECOND. I would appreciate any help! Thank you!

EDIT: My config file has,

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

which tells me to use me.github.com instead of github.com as host for repositories in the first Github account (with identity ~/.ssh/id_rsa) AND to use github.com for repositories in the second Github account (with identity ~/.ssh/id_rsa_SECOND). However, when I clone a repository in my personal account , using git@ **me**.github.com:username/hugo-academic.git does not work.

like image 382
ARAT Avatar asked Nov 08 '22 15:11

ARAT


1 Answers

This is an old question, but in case anybody else lands here with this problem, the solution (for me) is to include the github username in each block in ~/.ssh/config. As in:

# 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

In the github URL, change "github.com" to "github.com-1" or "github.com-2" as needed, so for example, you'd clone with:

git clone [email protected]:USERNAME-1/foo.git

instead of:

git clone [email protected]:USERNAME-1/foo.git

like image 193
stevelinberg Avatar answered Nov 15 '22 06:11

stevelinberg