We’re finally getting a Git server setup at work. Since I also happen to do a bit of open source contributing at work (usually via submitting patches for issues that effect us) and virtually every open source project and its brother is moving to Github lately, I could already see juggling these two systems would be an issue. I can’t use the same SSH key for both our internal Git server and Github for various reasons, and I wouldn’t I want to, really. Fortunately, it turns out managing multiple accounts with Git, and SSH in general, isn’t too bad.
I’ll walk you through doing this, assuming you don’t already have an SSH key or Github account (if you do, though, it’s no biggie, just make sure to back everything up and swap out a few obvious steps below).
- Sign up with Github.
- Download & install msysgit (chose to use the OpenSSH instead of Tortoise/Putty’s PLink when prompted).
- Open a Git Bash prompt (an icon is placed in the Start menu during msysgit’s installation).
Create your SSH key pairs, doing the following steps once for each email/account (internal work & external public ones, for instance):
ssh-keygen -t rsa -C "email@example.com"
- When it asks for the file to save to, specify the same folder it’s suggesting for the default one (i.e.
/c/Users/dmozingo/.ssh/) but name the file something different, based on whether it’s for the public or private key (maybe something like
- Enter a passphrase. I usually leave it blank as other guides suggest, trusting (perhaps mistakingly?) Window’s folder security to keep it safe for me.
- Navigate to the folder where you just created your SSH key pairs, and create a file named
Open the file in notepad and enter the following:
Host github.com HostName github.com User git PreferredAuthentications publickey IdentityFile /Users/dmozingo/.ssh/id_rsa_github Host work HostName workGitServername User dmozingo IdentityFile /Users/dmozingo/.ssh/id_rsa_work
You’ll have to do a few substitutions in the file, mainly for the work
HostNameand both section’s
IdentityFile‘s, if they’re different for your setup. The first line of each section specified the name you’ll use in “addressing” your Git commands later. By keeping the first one github.com, you won’t have to change anything when you follow along with other guides online.
- Now give GitHub the contents of your public/GitHub SSH key file (the id_rsa_github.pub from my example). You can do this on your account settings page.
- Still at the Git Bash prompt, enter
ssh-agent.exe bashto start the key manager. You’ll have to do this each time you use Git, unless someone (please?) can tell me a better way.
ssh-add.exe ~/.ssh/id_rsa_github, where the tilday (~) represents your home directory (C:\Users\username for Vista/7, C:\Documents and Settings\username for XP). This should point to the public SSH key file you made earlier. You’ll also have to do this each tiem you use Git, again, unless someone can set me straight here.
That should be it! Test it out by entering
ssh firstname.lastname@example.org. You should see something like this:
So while it’s definitely harder than not having to juggling multiple accounts, it’s not as bad as it sounds. Know a better way to do this? Please let me know!