<?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: Parth</title>
    <description>The latest articles on DEV Community by Parth (@itismowgli).</description>
    <link>https://dev.to/itismowgli</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%2F33969%2F28a53760-372a-47b9-ad9c-d64a59e37265.jpg</url>
      <title>DEV Community: Parth</title>
      <link>https://dev.to/itismowgli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/itismowgli"/>
    <language>en</language>
    <item>
      <title>Managing Multiple Github Accounts</title>
      <dc:creator>Parth</dc:creator>
      <pubDate>Fri, 23 Sep 2022 06:14:17 +0000</pubDate>
      <link>https://dev.to/itismowgli/managing-multiple-github-accounts-2m54</link>
      <guid>https://dev.to/itismowgli/managing-multiple-github-accounts-2m54</guid>
      <description>&lt;p&gt;Let’s see how many GitHub accounts can be managed from a single computer. In essence, it is a matter of balancing your git and ssh configurations, which is not as difficult as it may appear.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This guide is intended for Unix users.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Set up SSH Keys&lt;/strong&gt;&lt;br&gt;
On your local workstation, you can create a new SSH key. After generating the key, you can add it to your GitHub account to allow SSH authentication for Git activities.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: On March 15, 2022, GitHub increased security by removing obsolete, unsafe key types.&lt;br&gt;
DSA keys (ssh-dss) are no longer supported as of that date. You cannot add additional DSA keys to your own GitHub account.&lt;br&gt;
RSA keys (ssh-rsa) with a valid_after date prior to November 2, 2021 may continue to employ any signature algorithm. After that date, RSA keys must be produced using the SHA-2 signature technique. Some older clients may require an upgrade to utilise SHA-2 signatures.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Assume that your two Github accounts are named githubPersonal and githubWork.&lt;/p&gt;

&lt;p&gt;Create two SSH keys and store them in different files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd ~/.ssh
$ ssh-keygen -t rsa -C "personal@email.com"
# save it as id_rsa_personal when prompted
$ ssh-keygen -t rsa -C "work@email.com"
# save it as id_rsa_work when prompted
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the above commands, the following files are created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;id_rsa_personal
id_rsa_personal.pub
id_rsa_work
id_rsa_work.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Adding a new SSH key to your GitHub Personal account&lt;/strong&gt;&lt;br&gt;
Copy the SSH public key to your clipboard.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don’t add any newlines or whitespace.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pbcopy &amp;lt; ~/.ssh/id_rsa_personal.pub
# Copies the contents of the id_rsa_personal.pub file to your clipboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Tip: If &lt;code&gt;pbcopy&lt;/code&gt; isn't working, you can locate the hidden &lt;code&gt;.ssh&lt;/code&gt; folder, open the file in your favorite text editor, and copy it to your clipboard.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Add the key to your account:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to your Account Settings&lt;/li&gt;
&lt;li&gt;Click “SSH Keys” then “Add SSH key”&lt;/li&gt;
&lt;li&gt;Paste your key into the “Key” field and add a relevant title&lt;/li&gt;
&lt;li&gt;Click “Add key” then enter your GitHub password to confirm
Repeat the process for your GitHub work account.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Adding your SSH key to the ssh-agent&lt;/strong&gt;&lt;br&gt;
If you’re using macOS Sierra 10.12.2 or later, you will need to modify your &lt;code&gt;~/.ssh/config&lt;/code&gt; file to automatically load keys into the ssh-agent and store passphrases in your keychain.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, check to see if your &lt;code&gt;~/.ssh/config&lt;/code&gt; file exists in the default location.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ open ~/.ssh/config
&amp;gt; The file /Users/you/.ssh/config does not exist.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If the file doesn’t exist, create the file.&lt;br&gt;
&lt;code&gt;$ touch ~/.ssh/config&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open your &lt;code&gt;~/.ssh/config&lt;/code&gt; file, then modify the file to contain the following lines. If the name or path of your SSH key file is different from the example code, change the filename or path to match your setup.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# githubPersonal
Host personal
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa_personal
# githubWork
Host work
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa_work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Update stored identities&lt;/strong&gt;&lt;br&gt;
Clear currently stored identities:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ ssh-add -D&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add new keys:&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 -K ~/.ssh/id_rsa_personal
$ ssh-add -K ~/.ssh/id_rsa_work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test to make sure new keys are stored:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ ssh-add -l&lt;/code&gt;&lt;br&gt;
Test to make sure Github recognizes the keys:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ssh -T personal
Hi githubPersonal! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T work
Hi githubWork! You've successfully authenticated, but GitHub does not provide shell access.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Make default account global&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global user.name "personal"
git config --global user.email "personal@email.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Test PUSH&lt;/strong&gt;&lt;br&gt;
Make a new repository called “test-personal” in your personal account on Github.&lt;/p&gt;

&lt;p&gt;Back on your local machine, create a test directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd ~/documents
$ mkdir test-personal
$ cd test-personal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add a blank &lt;code&gt;readme.md&lt;/code&gt; file to Github and push:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ touch readme.md
$ git init
$ git add .
$ git commit -am "first commit"
$ git remote add origin git@personal:githubPersonal/test-personal.git
$ git push origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Notice how we’re using the custom account, &lt;code&gt;git@personal&lt;/code&gt;, instead of &lt;code&gt;git@github.com&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Repeat the process for your githubWork account.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test PULL&lt;/strong&gt;&lt;br&gt;
Add some text to the &lt;code&gt;readme.md&lt;/code&gt; file in your personal account on Github.&lt;/p&gt;

&lt;p&gt;Now Pull and merge the changes by running the following command within the test-personal directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git pull origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, repeat this for your githubWork account.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clone a repository&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone git@personal:githubPersonal/test-personal.git
# For personal repository
$ git clone git@work:githubWork/test-personal.git
# For Work repository
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you add local config to the project folder if you’re using a non-default(githubWork) account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone git@work:githubWork/test-personal.git
$ git config user.name "work"
$ git config user.email "work@email.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>github</category>
      <category>webdev</category>
      <category>macos</category>
    </item>
  </channel>
</rss>
