<?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: Nullpod</title>
    <description>The latest articles on DEV Community by Nullpod (@jp-nullpod).</description>
    <link>https://dev.to/jp-nullpod</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%2Forganization%2Fprofile_image%2F6545%2F0eae8f03-f41d-41ca-a56f-d272677c5aee.png</url>
      <title>DEV Community: Nullpod</title>
      <link>https://dev.to/jp-nullpod</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jp-nullpod"/>
    <language>en</language>
    <item>
      <title>Utilizing GitHub accounts on Ubuntu with multiple SSH keys</title>
      <dc:creator>emmanuel-nullpod</dc:creator>
      <pubDate>Wed, 21 Feb 2024 14:05:15 +0000</pubDate>
      <link>https://dev.to/jp-nullpod/utilizing-github-accounts-on-ubuntu-with-multiple-ssh-keys-303l</link>
      <guid>https://dev.to/jp-nullpod/utilizing-github-accounts-on-ubuntu-with-multiple-ssh-keys-303l</guid>
      <description>&lt;p&gt;In the dynamic realm of software development, it's not uncommon for developers to find themselves juggling multiple GitHub accounts—one for work and another for personal projects. Navigating this dual identity on Ubuntu/Mac requires a thoughtful approach, particularly when it comes to managing SSH keys. This article serves as a practical guide to seamlessly use two or more GitHub accounts on Ubuntu/Mac by employing multiple SSH keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Dilemma
&lt;/h2&gt;

&lt;p&gt;Managing work and personal GitHub accounts simultaneously poses a unique challenge. A key aspect of addressing this challenge is the need for separate SSH keys, ensuring secure and efficient authentication for each account.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding SSH Keys
&lt;/h2&gt;

&lt;p&gt;SSH keys play a pivotal role in secure authentication. By utilizing distinct keys for different GitHub accounts, developers can maintain a clear separation between their professional and personal coding endeavours.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generating SSH Keys for Each GitHub Account
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Work Account(example):
&lt;/h3&gt;

&lt;p&gt;Open the terminal and generate an SSH key using: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;ssh-keygen -t rsa -b 4096 -C "your-email@work.com"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Save the key to an appropriate directory. By default it is in the “~/.ssh” directory you can keep it that way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwvnmqqlt320ux055dq7e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwvnmqqlt320ux055dq7e.png" alt="Image description" width="800" height="141"&gt;&lt;/a&gt;&lt;br&gt;
If you want to give a specific name to your key, it can be changed by renaming the file in which you want the key to be saved in. Renaming of keys can be used to properly identify different keys you saved.&lt;/p&gt;
&lt;h3&gt;
  
  
  Personal Account:
&lt;/h3&gt;

&lt;p&gt;Repeat the process with a different email for your personal GitHub account.&lt;/p&gt;
&lt;h2&gt;
  
  
  Configuring SSH Config File
&lt;/h2&gt;

&lt;p&gt;To manage multiple SSH keys effectively, edit your SSH config file. Add the following lines:&lt;br&gt;
Once the Keys properly generated, they should be found in the “~/.ssh” directory. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqwejp2b8ldbz7l16o6xz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqwejp2b8ldbz7l16o6xz.jpg" alt="Image description" width="800" height="58"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If all the key generated are available, then head to your different GitHub accounts on &lt;a href="https://github.com"&gt;GitHub.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Head  to the your profile settings and select “SSH and GPG keys” and click “New SSH key”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy6errbe7rvi5gxehzzea.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy6errbe7rvi5gxehzzea.jpg" alt="Image description" width="800" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You need to add you generated public key that can be obtained from reading the public keys generated. With the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat ~/.ssh/&amp;lt;your_key_name&amp;gt;.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy and paste the result from the public key in the Key text area provided on your GitHub and click “Add SSH key”.&lt;br&gt;
Repeat the step for both GitHub accounts and any accounts you wish to add this way. &lt;/p&gt;
&lt;h2&gt;
  
  
  Bash Code
&lt;/h2&gt;

&lt;p&gt;To write the bash code go to the “.shh” folder and create a file to create a “config” text file using vim to properly separate the different public keys. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open your terminal&lt;/li&gt;
&lt;li&gt;Go to the SSH folder using &lt;code&gt;cd ~/.ssh&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create a config file using the command “vim config”.&lt;/li&gt;
&lt;li&gt;Insert the correct text below in the config file by replacing the data with your private data.&lt;/li&gt;
&lt;li&gt;Check that the content of the config file is properly inserted using &lt;code&gt;cat ~/.ssh/config&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw8rslficm7kkoxooi6oy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw8rslficm7kkoxooi6oy.png" alt="Image description" width="800" height="726"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Personal account
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host github.com-personal
            HostName github.com
            IdentityFile ~/.ssh/&amp;lt;Your private key&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Work account
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host github.com-work
            HostName github.com
        IdentityFile ~/.ssh/&amp;lt;Your work key&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Bash Testing
&lt;/h2&gt;

&lt;p&gt;Testing the Configuration&lt;/p&gt;
&lt;h3&gt;
  
  
  Work account
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -T git@github.com-work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Personal account
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -T git@github.com-personal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;While testing you might be prompted to enter a password to unlock the private key. Enter the password given to the key that you generate in the steps above to continue with the operation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiwl9siv1gw1s23s38tsb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiwl9siv1gw1s23s38tsb.png" alt="Image description" width="800" height="543"&gt;&lt;/a&gt;&lt;br&gt;
Here is what should be seen when the keys are properly distributed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fruvl10wxbb0n5129fsuf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fruvl10wxbb0n5129fsuf.png" alt="Image description" width="800" height="74"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Adding SSH Keys to the Authentication Agent
&lt;/h2&gt;

&lt;p&gt;After configuring multiple SSH keys and testing the setup, you can enhance the workflow by using the &lt;code&gt;ssh-add&lt;/code&gt; command. This command adds private keys to the SSH authentication agent, eliminating the need to enter the passphrase every time you use the keys.&lt;/p&gt;

&lt;p&gt;Open a terminal and run the following commands for each key:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faqnc9ujkfkrzot0fa70p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faqnc9ujkfkrzot0fa70p.png" alt="Image description" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: You can then list all the ssh-keys information to verify that your keys are well implemented. By doing the command&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Organizing Workspaces
&lt;/h2&gt;

&lt;p&gt;Consider organizing your workspaces effectively, keeping work and personal projects in separate directories. This helps maintain a clear distinction between the two.&lt;/p&gt;

&lt;h2&gt;
  
  
  Updating Git Configurations
&lt;/h2&gt;

&lt;p&gt;Update your Git configurations to align with the new SSH key setup. Ensure consistency across all relevant settings for a smooth experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: A Seamless Workflow
&lt;/h2&gt;

&lt;p&gt;By following these steps, you've successfully configured multiple SSH keys for your dual GitHub accounts on Ubuntu/Mac. This setup ensures a harmonious balance between your professional and personal coding pursuits, enhancing both security and workflow.&lt;/p&gt;

</description>
      <category>github</category>
      <category>ubuntu</category>
      <category>ssh</category>
    </item>
  </channel>
</rss>
