title: How to setup two different Github accounts for two different repositories through SSH?
body: <p>Before start I should say I have read a lot of topics (listed at the end of this post) about this issue but none is working for me or maybe I am missing something trivial in here.</p>
  
  <p>At first I did clone the repository using HTTPS but then I switched to SSH following the docs from <a href="https://help.github.com/articles/changing-a-remote-s-url/" rel="nofollow noreferrer">here</a>. I did generate each of the SSH key and add them to the <code>ssh-agent</code> following the docs from <a href="https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/" rel="nofollow noreferrer">here</a>.</p>
  
  <p>In a few lines (fake data used, <code>~</code> means my home directory) this is what I've done:</p>
  
  <pre class="lang-bash prettyprint-override"><code>$ ssh-keygen -t rsa -b 4096 -C "first@gmail.com"
  Enter a file in which to save the key (~/.ssh/id_rsa): [Press enter]
  Enter passphrase (empty for no passphrase): [Type a passphrase]
  Enter same passphrase again: [Type passphrase again]
  
  $ ssh-keygen -t rsa -b 4096 -C "second@gmail.com"
  Enter a file in which to save the key (~/.ssh/id_rsa_second): [Press enter]
  Enter passphrase (empty for no passphrase): [Type a passphrase]
  Enter same passphrase again: [Type passphrase again]
  
  $ eval "$(ssh-agent -s)"
  Agent pid 12697
  
  $ ssh-add ~/.ssh/id_rsa
  Identity added: ~/.ssh/id_rsa (~/.ssh/id_rsa)
  
  $ ssh-add ~/.ssh/id_rsa_second
  Identity added: ~/.ssh/id_rsa_second (~/.ssh/id_rsa_second)
  
  $ ssh-add -l
  4096 SHA256:gb+Gn4SqiyAP5ABUsmX6Xz11RHTSvDsWgEE5P2R2VTE ~/.ssh/id_rsa (RSA)
  4096 SHA256:yxWMompayDNtYjv5y+FfJl7OpQ5Qu90kPgdXXvx6DRA ~/.ssh/id_rsa_second (RSA)
  </code></pre>
  
  <p>The next step was create the <code>~/.ssh/config</code> file with the following content:</p>
  
  <pre><code>#first account
  Host github.com-first
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa
  
  #second account
  Host github.com-second
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_second
  </code></pre>
  
  <p>I stopped here and give this a try by adding the SSH pub key for <code>id_rsa_second</code> to the repository where I want to use it (this doesn't need explanation). Next <code>git pull</code>:</p>
  
  <pre class="lang-bash prettyprint-override"><code>$ git pull
  Bad owner or permissions on /home/rperez/.ssh/config
  fatal: Could not read from remote repository.
  
  Please make sure you have the correct access rights
  and the repository exists.
  </code></pre>
  
  <p>Then I tried the following:</p>
  
  <ul>
  <li><p>Change the <code>.git/config</code> file to the following:</p>
  
  <pre><code>[remote "origin"]
      url = git@github.com-second:repo/repo.git
      fetch = +refs/heads/*:refs/remotes/origin/*
  </code></pre></li>
  </ul>
  
  <p>But it didn't work and by this I mean I got exactly the same error as before.</p>
  
  <p>What I am doing wrong? What I am missing?</p>
  
  <p>What I have read:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/35823162/how-to-properly-configure-ssh-keys-to-multiple-remote-accounts-involving-github">How to properly configure ssh keys to multiple remote accounts involving github and bitbucket?</a></li>
  <li><a href="https://stackoverflow.com/questions/13552809/github-multiple-account-setup">GitHub: Multiple account setup</a></li>
  <li><a href="https://stackoverflow.com/questions/3860112/multiple-github-accounts-on-the-same-computer">Multiple github accounts on the same computer?</a></li>
  <li><a href="https://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574" rel="nofollow noreferrer">Quick Tip: How to Work with GitHub and Multiple Accounts</a></li>
  <li><a href="https://stackoverflow.com/questions/40034769/cant-get-multiple-ssh-keys-to-work-for-multiple-github-accounts">Can&#39;t get Multiple SSH keys to work for multiple github accounts</a></li>
  <li><a href="https://gist.github.com/jexchan/2351996" rel="nofollow noreferrer">Multiple SSH Keys settings for different github account</a></li>
  </ul>
  
  <blockquote>
    <p>Note: The title may seem confusing but it is correct because it is what I want to achieve I am just talking about one example but at the end I should be able to setup more than one account pointing to different repositories.</p>
  </blockquote>