4

I want to work on my personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account .

In my case , I will not be able to add my personal GitHub account as a collaborator for "Work" account's project . I was thinking I can add a new key pair on my office computer , and add it to my personal GitHub account . But will I be able to work on both "Work" and "Personal" repos seamlessly that way ? What's the best way to do this ?

Emil
  • 1,240
  • 1
  • 15
  • 27
  • Have you tried adding that same SSH key to your Personal GitHub account to see if it works? – Blender Aug 22 '12 at 05:46
  • @Blender - Yea tried that , since my office computer's SSH key is already added to another GitHub account , it won't let me add the same key to my personal GitHub . It says "key already in use" – Emil Aug 22 '12 at 07:08

2 Answers2

8

You can add as many public:private key you want, the idea being to register them in %HOME%/.ssh/config file, in order for you to define remote with ssh addresses like:

workgh:Work
persgh:Personal

See "change github account mac command line" as an example of an ssh/config file.

In your case:

#Personal GitHub
Host persgh
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_perso

#Personal Work
Host workgh
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_work

Reusing the same ssh key in different environment is genrally frowned upon.
See this SO question to generate multiple ssh keys non-interactively.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I don't understand! How it's gonna distinguish between same hosts to know when uses workRSA, when uses homeRSA!? – Dr.jacky Aug 07 '20 at 20:44
  • 1
    @Dr.jacky because of the private key: each entry references its own private key, whose public key has been registered to a different user. – VonC Aug 07 '20 at 21:47
0

Coming from a Ruby background , I ended up using "gas" ruby gem . Adding git users was a breeze and it takes care of switching git users along with the keys with a simple command on the terminal :

gas use <nickname>

Here's this link to the gem : https://github.com/walle/gas

A video on it's features : http://www.youtube.com/watch?v=-W2vSTwJWJc

Emil
  • 1,240
  • 1
  • 15
  • 27