In mucking about trying to become a certified (not certifiable!) SWC
instructor, I managed to mangle Github pretty badly.  But, something
came of it that, if it isn't something you've done for just ages, you
might find useful if you need to have two Github identities going at
once and you like to use ssh keys.

I have one identity, justbennet, and another carpenterbennet.  One I
use for my real self, and one I use for workshops (say).  Under normal
circumstances, if I check my git configuration for repos from each
account, it would look something like one of these two entries:

[email protected]:carpenterbennet/r-novice-gapminder.git

[email protected]:justbennet/r-novice-gapminder.git

My One True ssh key only works with one of those.  Maybe it's possible
to munge that line with ssh options to specify the key to use; I
didn't find one.  But, I did find that ~/.ssh/config can be used.  My
first pass was to use


Host github.com
    IdentityFile /Users/bennet/.ssh/justbennet
    # IdentityFile /Users/bennet/.ssh/carpenterbennet


and I would modify the file when I needed the other key.  "But this
solution did not satisfy me fully."[1]  Then something clicked, or
snapped, and consulting the man page for ssh_config, I arrived at
this.

First, modify the ~/.ssh/config file so it has something like this in it


Host carpenter-git
    HostName github.com
    IdentityFile /Users/bennet/.ssh/carpenterbennet
Host just-git
    HostName github.com
    IdentityFile /Users/bennet/.ssh/justbennet


Then, for your existing git configurations, change the hostname used
from github.com to what appears as the Host in your ~/.ssh/config,
thusly,

remote.origin.url=git@carpenter-git:carpenterbennet/r-novice-gapminder.git

remote.origin.url=git@just-git:justbennet/r-novice-gapminder.git


If you want to clone a repo, make the same substitution on the clone
command, i.e.,

$ git clone [email protected]:carpenterbennet/r-novice-gapminder.git

would become instead

$ git@carpenter-git:carpenterbennet/r-novice-gapminder.git

or

$ git clone git@just-git:justbennet/r-novice-gapminder.git

and it appears that git takes that hostname and stores it in its
config, so if you clone that way you don't have to remember to modify
git's configuration after.

I did this from a Mac, but it should work equally well from Linux, BSD, et al.

Sorry for the noise if that's old hat to everyone, but I thought it
was a neat trick and maybe someone might find some use from it.

-- bennet

[1] Samuel Beckett, Molloy, Malone Dies, The Unnamable, (New York:
Knopf 1997), somewhere in pp 75–81.

_______________________________________________
Discuss mailing list
[email protected]
http://lists.software-carpentry.org/mailman/listinfo/discuss_lists.software-carpentry.org

Reply via email to