<?xml version="1.0" encoding="UTF-8"?>
<guide>
  <body>&lt;p style=&quot;background:#fefeb4;border:1px solid #dddddd;font-weight:bold;padding:0.5em 1em;&quot;&gt;The solution detailed in this guide is fairly complex and may not be ideal for most users.&lt;br /&gt;
We recommend you check out the solutions detailed in [[Managing multiple clients and their repositories]] first.&lt;/p&gt;
&lt;h2&gt;The Problem&lt;/h2&gt;
&lt;p&gt;One might encounter a situation where two GitHub accounts might be necessary. Naturally, I mean two &lt;strong&gt;pay&lt;/strong&gt; accounts in order to remain in good standing according to the &lt;span class=&quot;caps&quot;&gt;TOS&lt;/span&gt; (or one free and one pay account). And we all want to stay in good standing with GitHub since they were awesome enough to make this great web application, right? Nevertheless, with that said, one might find one&amp;#8217;s self in this situation.&lt;/p&gt;
&lt;p&gt;A problem that one is likely to encounter in this situation is attempting to maintain two or more repositories that use more than one GitHub account. Using the default public/private key setup that GitHub suggests works great when only one account is involved, but when one attempts to clone a repository using a second account, by default, git attempts to use the first account, which is likely declined resulting in failure.&lt;/p&gt;
&lt;p&gt;This article is assuming that you already have two git accounts created and that you already have the first &lt;a href=&quot;http://github.com/guides/providing-your-ssh-key&quot;&gt;key pair&lt;/a&gt; in place on both your local system and on GitHub.&lt;/p&gt;
&lt;h2&gt;Generating a Second Key Pair&lt;/h2&gt;
&lt;p&gt;Read this section &lt;span class=&quot;caps&quot;&gt;COMPLETELY&lt;/span&gt; before actually doing anything.  You could easily get yourself into a lot of trouble if you do not.  GitHub identifies which account you are attempting to access by the &lt;span class=&quot;caps&quot;&gt;SSH&lt;/span&gt; key that you give it.  To this end, you cannot use the same key pair for more than one GitHub account.  You will need to follow the instructions given in the guide entitled &lt;a href=&quot;http://github.com/guides/providing-your-ssh-key&quot;&gt;Providing your &lt;span class=&quot;caps&quot;&gt;SSH&lt;/span&gt; Key&lt;/a&gt;.  I think it would be unwise to reproduce part of that guide here.&lt;/p&gt;
&lt;p&gt;Upon executing the ssh-keygen command, you will be presented with a prompt similar to the following:&lt;/p&gt;
&lt;pre class=&quot;console&quot;&gt;Enter file in which to save the key (/Users/tom/.ssh/id_rsa):&lt;/pre&gt;
&lt;p&gt;&lt;b&gt;&lt;span class=&quot;caps&quot;&gt;WARNING&lt;/span&gt;&lt;/b&gt;: If you already had a key pair and are using it for anything at all, do &lt;span class=&quot;caps&quot;&gt;NOT&lt;/span&gt; leave this blank nor should you use the default file suggested. It will overwrite your primary key pair, and that would be very bad.&lt;/p&gt;
&lt;p&gt;Instead of using &amp;#8220;id_rsa&amp;#8221;, you should use something like &amp;#8220;id_rsa_github_useraccount&amp;#8221; to denote the purpose of the key.  So ultimately, you would enter:&lt;/p&gt;
&lt;pre  class=&quot;console&quot;&gt;/Users/tom/.ssh/id_rsa_github_useraccount&lt;/pre&gt;
&lt;h2&gt;Placing the Public and Private Keys&lt;/h2&gt;
&lt;h3&gt;Private Key&lt;/h3&gt;
&lt;p&gt;You will not actually be putting the private key anywhere, but instead only referencing it.  For this, you will need to open the &lt;span class=&quot;caps&quot;&gt;SSH&lt;/span&gt; config (~/.ssh/config) file in your favorite editor.  Once in this file, you should add the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# GitHub for cylence
Host github-tom
  HostName github.com
  User git
  IdentityFile /Users/tom/.ssh/id_rsa_git_tom&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The top line is a simple comment, you can leave this out of you choose. Next is the name of the Host, this is what you will use when referencing this connection and after the word &amp;#8220;Host&amp;#8221; followed by a space is completely arbitrary. The HostName must be &amp;#8220;github.com&amp;#8221; as is the same with the User.Notice that it is still &amp;#8220;git&amp;#8221; and not an account name.  Lastly, the IdentityFile line must contain a non-reative path to your newly created private key (&lt;span class=&quot;caps&quot;&gt;NOT&lt;/span&gt; ending with .pub).&lt;/p&gt;
&lt;h3&gt;Public Key&lt;/h3&gt;
&lt;p&gt;Once the private key is properly being referenced, you must tell GitHub what the public key is. You do this by accessing your &lt;a href=&quot;http://github.com/account&quot;&gt;account page&lt;/a&gt; on GitHub.  Place your public key (including the carriage return at the end) into the &amp;#8220;&lt;span class=&quot;caps&quot;&gt;SSH&lt;/span&gt; Public Keys&amp;#8221; textarea field.&lt;/p&gt;
&lt;h2&gt;Using the Newly Created Keys&lt;/h2&gt;
&lt;p&gt;From here on, everything is the same except for one component. To present an example, we will look at a standard clone command.&lt;/p&gt;
&lt;pre class=&quot;console&quot;&gt;git clone git@github.com:account/repository.git&lt;/pre&gt;
&lt;p&gt;Traditionally, this command consists of &amp;#8220;git clone&amp;#8221;, the command to be performed, followed by a mostly ordinary ssh connection.&lt;/p&gt;
&lt;pre&gt;user@domain:path/somewhere/file.extension&lt;/pre&gt;
&lt;p&gt;What we will be changing is the domain portion of this line.  Instead of using the domain &amp;#8220;github.com&amp;#8221;, we will be specifying the pre-configured &lt;span class=&quot;caps&quot;&gt;SSH&lt;/span&gt; connection we built earlier.  It is referenced using the Host line.  Using our previous example, the end result would look like this:&lt;/p&gt;
&lt;pre class=&quot;console&quot;&gt;git clone git@github-tom:account/repository.git&lt;/pre&gt;
&lt;h2&gt;Notes&lt;/h2&gt;
&lt;p&gt;If you are running keychain to manage your &lt;span class=&quot;caps&quot;&gt;SSH&lt;/span&gt; keys you may need to stop ssh-agent and add the new key to your keyring for it to work properly.  If you are seeing failed access to your repositories as your other user, even though you&amp;#8217;re configured to use the new key with your correct user you may wish to give this a try. On &lt;span class=&quot;caps&quot;&gt;OSX&lt;/span&gt; Leopard is built in keychain integration, so either don&amp;#8217;t store your passphrase in keychain or don&amp;#8217;t use passphrase for your private key at all.&lt;/p&gt;
&lt;p&gt;Regarding multiple local keys and ssh-agent, be sure to add each key with ssh-add, you can also try prefixing your git commands (when interacting with the remote repo) with SSH_AUTH_SOCK=&amp;quot;&amp;quot;, which will make ssh not use the ssh-agent.&lt;/p&gt;</body>
  <created-at type="datetime">2008-04-24T16:24:28-07:00</created-at>
  <id type="integer">42</id>
  <permalink>multiple-github-accounts</permalink>
  <title>Multiple GitHub Accounts</title>
  <updated-at type="datetime">2009-10-19T05:13:40-07:00</updated-at>
  <user-id type="integer">140313</user-id>
</guide>
