<?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>DEV Community: Dinesh Papineni</title>
    <description>The latest articles on DEV Community by Dinesh Papineni (@dineshpapineni).</description>
    <link>https://dev.to/dineshpapineni</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%2F415724%2F4d8755c4-297f-42ab-ba07-2a4c4acdd81e.jpeg</url>
      <title>DEV Community: Dinesh Papineni</title>
      <link>https://dev.to/dineshpapineni</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dineshpapineni"/>
    <language>en</language>
    <item>
      <title>How to configure multiple git accounts with ssh keys on macOS</title>
      <dc:creator>Dinesh Papineni</dc:creator>
      <pubDate>Mon, 17 Aug 2020 01:59:14 +0000</pubDate>
      <link>https://dev.to/dineshpapineni/how-to-configure-multiple-git-accounts-with-ssh-keys-on-mac-os-gf9</link>
      <guid>https://dev.to/dineshpapineni/how-to-configure-multiple-git-accounts-with-ssh-keys-on-mac-os-gf9</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KWuZ20WD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r414yl8zn8xpjp6rbibm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KWuZ20WD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r414yl8zn8xpjp6rbibm.png" alt="macos git github"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Clean up your ssh directory and agent&lt;/strong&gt;
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to ssh directory &lt;strong&gt;~/.ssh&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Clean up the existing configuration by deleting config, known_hosts and other ssh public and private key files&lt;/li&gt;
&lt;li&gt;Also clean up old keys from the ssh agent
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-add -D
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Create a new ssh keys using ssh keygen&lt;/strong&gt;
&lt;/h1&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Steps for creating keys for enterprise github account&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Generate ssh keys for enterprise github with work email address&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t rsa -b 4096 -C
"your_work_email@work_domain.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On prompt enter the key name for work account &lt;strong&gt;&lt;em&gt;id_rsa_work&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the next prompt enter a passphrase for the ssh key&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You should see two new files named &lt;em&gt;id_rsa_work&lt;/em&gt; and &lt;em&gt;id_rsa_work.pub&lt;/em&gt; in your ssh directory &lt;strong&gt;~/.ssh&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Repeat the steps for creating keys for personal github account&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Generate ssh keys for personal github with personal email address&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t rsa -b 4096 -C 
"your_personal_email@domain.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On prompt enter the key name for personal account &lt;strong&gt;&lt;em&gt;id_rsa_personal&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the next prompt enter the passphrase for the ssh key&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You should see two new files named &lt;em&gt;id_rsa_personal&lt;/em&gt; and &lt;em&gt;id_rsa_personal.pub&lt;/em&gt; in your ssh directory &lt;strong&gt;~/.ssh&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Add keys to ssh agent using the config&lt;/strong&gt;
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Start the ssh agent in your terminal&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eval "$(ssh-agent -s)"
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a new config file&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch ~/.ssh/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add keys to ssh agent&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-add -K id_rsa_work
ssh-add -K id_rsa_personal
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Verify keys are stored in ssh agent&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-add -l
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the host and ssh information to the config file. Replace the work domain  name below with your enterprise github hostname. Example- github.google.com&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host work
  HostName github.&amp;lt;workdomain&amp;gt;.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa_work
  ServerAliveInterval 600
  TCPKeepAlive yes
  IPQoS=throughput
Host personal
  HostName github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa_personal
  ServerAliveInterval 600
  TCPKeepAlive yes
  IPQoS=throughput
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; We have added additional config here to keep the server connection alive in order to avoid connection drops. This helps in case you are seeing following failure:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Broken pipe fatal: Could not read from remote repository.  Please make sure you have the correct access rights and the repository exists.&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Add SSH keys to your github accounts&lt;/strong&gt;
&lt;/h1&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Steps for adding ssh key to enterprise github account&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Copy your work public ssh key using the following command&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pbcopy &amp;lt; id_rsa_work.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the browser navigate to your enterprise github account(&lt;a href="https://github.workdomain.com"&gt;https://github.workdomain.com&lt;/a&gt;). From the top right drop down click &lt;strong&gt;Settings&lt;/strong&gt;. Now click on the SSH and GPG keys on the left navigation bar.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click New SSH Key button. Enter the name of your choice and paste the key copied in step 1 of this section. Click Add SSH key&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Repeat the steps for adding ssh key for personal github account&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Copy your personal public ssh key using the following command&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pbcopy &amp;lt; id_rsa_personal.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the browser navigate to your personal github accounts(&lt;a href="https://github.com"&gt;https://github.com&lt;/a&gt;). From the top right drop down click &lt;strong&gt;Settings&lt;/strong&gt;. Now click on the SSH and GPG keys on the left navigation bar.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click New SSH Key button. Enter the name of your choice and paste the key copied in step 1 of this section. Click Add SSH key&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Verify  SSH keys are added to your github accounts&lt;/strong&gt;
&lt;/h1&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Steps for verifying ssh key for work account is recognized by github&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Enter the below command in terminal&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -T work
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When prompted to add the hosts to your know_hosts file type &lt;strong&gt;yes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;The authenticity of host 'github.&amp;lt;work_domain&amp;gt;.com &lt;br&gt;
(&amp;lt;work_domain_ip)' can't be established.&lt;br&gt;
ECDSA key fingerprint is &amp;lt;key&amp;gt;.Are you sure you want to &lt;br&gt;
continue connecting (yes/no/[fingerprint])? yes&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You should see a confirmation that you are connected&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Warning: Permanently added 'github.&amp;lt;work_domain&amp;gt;.com, &lt;br&gt;
&amp;lt;work_domain_ip&amp;gt;' (ECDSA) to the list of known hosts.&lt;br&gt;
Hi &amp;lt;work_user&amp;gt;! You've successfully authenticated, but &lt;br&gt;
GitHub does not provide shell access.&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Repeat the steps to verify ssh key for personal account is recognized by github&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Enter the below command in terminal&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -T personal
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When prompted to add the hosts to your know_hosts file type &lt;strong&gt;yes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;The authenticity of host 'github.com (&amp;lt;domain_ip&amp;gt;)' &lt;br&gt;
can't be established.&lt;br&gt;
RSA key fingerprint is &amp;lt;key&amp;gt;.Are you sure you want to &lt;br&gt;
continue connecting (yes/no/[fingerprint])? yes&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You should see a confirmation that you are connected&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Warning: Permanently added 'github.com,&amp;lt;domain_ip&amp;gt;' (RSA) &lt;br&gt;
to the list of known hosts.&lt;br&gt;
Hi &amp;lt;personal_user&amp;gt;! You've successfully authenticated, but &lt;br&gt;
GitHub does not provide shell access.&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The ssh agent on mac will lose the keys on reboot. You can resolve that by simply running this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-add -A
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Additional references:&lt;/strong&gt;
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent"&gt;https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account"&gt;https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>github</category>
      <category>ssh</category>
      <category>macos</category>
      <category>development</category>
    </item>
  </channel>
</rss>
