<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Prasanna</title>
    <description>The latest articles on Forem by Prasanna (@worldofprasanna).</description>
    <link>https://forem.com/worldofprasanna</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F72771%2F107eef3f-8b86-4f0b-acad-8cb84ce2665d.png</url>
      <title>Forem: Prasanna</title>
      <link>https://forem.com/worldofprasanna</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/worldofprasanna"/>
    <language>en</language>
    <item>
      <title>Manage ssh keys for Multiple Github accounts</title>
      <dc:creator>Prasanna</dc:creator>
      <pubDate>Sun, 19 Jul 2020 14:19:49 +0000</pubDate>
      <link>https://forem.com/worldofprasanna/manage-ssh-keys-for-multiple-github-accounts-2nf3</link>
      <guid>https://forem.com/worldofprasanna/manage-ssh-keys-for-multiple-github-accounts-2nf3</guid>
      <description>&lt;p&gt;Currently, I am working for a company where they create a Github account using the company’s email id and all the repository access would be given to that Github account.&lt;br&gt;
But I have a personal Github account as well and I am quite active in that too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Now the problem is, How to manage the SSH keys for both the GitHub accounts. Git by default takes the ~/.ssh/id_rsa(.pub) keys and we can’t add the same ssh key in both the GitHub account.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;We can manage multiple Github accounts using the ssh config file.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Create a new ssh key pair&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Generate a new ssh key pair using the company’s email id. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ssh-keygen -t rsa -b 4096 -C "&lt;a href="mailto:prasanna@his-company.com"&gt;prasanna@his-company.com&lt;/a&gt;"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the prompt, specify a different file name. &lt;br&gt;
Eg: /User/prasanna/.ssh/id_rsa_my_company&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Add the ssh key to the ssh-agent&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now add the generated key using the ssh-add command.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ssh-add ~/.ssh/id_rsa_my_company&lt;br&gt;
Output:&lt;br&gt;
Identity added: /Users/prasanna/.ssh/id_rsa_my_company (&lt;a href="mailto:prasanna@his-company.com"&gt;prasanna@his-company.com&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Add the id_rsa_my_company.pub key to your company Github account.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cat ~/.ssh/id_rsa_my_company.pub|pbcopy&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Update the hosts in the ssh config file&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Update the config file (~/.ssh/config) with these values and it should have entry to for you personal Github account,&lt;/p&gt;

&lt;blockquote&gt;
&lt;h6&gt;
  
  
  My Company Github Account
&lt;/h6&gt;

&lt;p&gt;Host github-mycompany.com&lt;br&gt;
HostName github.com&lt;br&gt;
User git&lt;br&gt;
IdentityFile ~/.ssh/id_rsa_my_company&lt;/p&gt;
&lt;h6&gt;
  
  
  Personal Github Account
&lt;/h6&gt;

&lt;p&gt;Host github.com&lt;br&gt;
HostName github.com&lt;br&gt;
User git&lt;br&gt;
IdentityFile ~/.ssh/id_rsa&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Clone your personal Github and company Github projects&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can clone your personal private projects using the command,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git clone &lt;a href="mailto:git@github.com"&gt;git@github.com&lt;/a&gt;:your-github-account/private-repo.git&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can clone your company ‘s private projects using the command,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git clone &lt;a href="mailto:git@github-mycompany.com"&gt;git@github-mycompany.com&lt;/a&gt;:company-acc/private.git&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s it. Hope it will be useful. Let me know If you have any questions in the comment section.&lt;/p&gt;

</description>
      <category>github</category>
      <category>ssh</category>
      <category>productivity</category>
      <category>git</category>
    </item>
  </channel>
</rss>
