<?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: A N M JUBAER</title>
    <description>The latest articles on DEV Community by A N M JUBAER (@jubaerad).</description>
    <link>https://dev.to/jubaerad</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%2F1209121%2Ff06bc462-361c-4571-86bd-3ea58ef86f0d.jpeg</url>
      <title>DEV Community: A N M JUBAER</title>
      <link>https://dev.to/jubaerad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jubaerad"/>
    <language>en</language>
    <item>
      <title>road to ssh (for multiple github account) on windows machine!</title>
      <dc:creator>A N M JUBAER</dc:creator>
      <pubDate>Wed, 19 Feb 2025 09:33:20 +0000</pubDate>
      <link>https://dev.to/jubaerad/road-to-ssh-for-multiple-github-account-on-windows-machine-3bpl</link>
      <guid>https://dev.to/jubaerad/road-to-ssh-for-multiple-github-account-on-windows-machine-3bpl</guid>
      <description>&lt;p&gt;credit: &lt;a href="https://www.youtube.com/@jcmiron2414" rel="noopener noreferrer"&gt;jcmiron&lt;/a&gt;&lt;br&gt;
i am trying to add both my work and personal GitHub account to same &lt;br&gt;
device.&lt;/p&gt;

&lt;p&gt;so the steps involved are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;enable and start (if not all ready) OpenSSH Authentication Agent. you can do it from the services or by running command below&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c"&gt;# start the ssh-agent in the background&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;Get-Service&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ssh-agent&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Set-Service&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-StartupType&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Manual&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;Start-Service&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ssh-agent&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;create ssh key at local machine for each account (here work and personal). follow this link for in depth explanation &lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key" rel="noopener noreferrer"&gt;create ssh&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;add a config file in the same directory as .ssh folder from step 1. in my case, the content of this config file is:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c"&gt;# Work GitHub
&lt;/span&gt;&lt;span class="err"&gt;Host&lt;/span&gt;  &lt;span class="err"&gt;work&lt;/span&gt; &lt;span class="c"&gt;# alias for work
&lt;/span&gt;&lt;span class="err"&gt;Hostname&lt;/span&gt;  &lt;span class="err"&gt;github.com&lt;/span&gt;
&lt;span class="err"&gt;User&lt;/span&gt;  &lt;span class="err"&gt;git&lt;/span&gt;
&lt;span class="err"&gt;IdentityFile&lt;/span&gt;  &lt;span class="err"&gt;~/.ssh/work_key&lt;/span&gt; &lt;span class="c"&gt;# private key for work
&lt;/span&gt;&lt;span class="err"&gt;IdentitiesOnly&lt;/span&gt;  &lt;span class="err"&gt;yes&lt;/span&gt;

&lt;span class="c"&gt;# Personal GitHub
&lt;/span&gt;&lt;span class="err"&gt;Host&lt;/span&gt;  &lt;span class="err"&gt;per&lt;/span&gt; &lt;span class="c"&gt;# alias for personal
&lt;/span&gt;&lt;span class="err"&gt;Hostname&lt;/span&gt;  &lt;span class="err"&gt;github.com&lt;/span&gt;
&lt;span class="err"&gt;User&lt;/span&gt;  &lt;span class="err"&gt;git&lt;/span&gt;
&lt;span class="err"&gt;IdentityFile&lt;/span&gt;  &lt;span class="err"&gt;~/.ssh/personal_key&lt;/span&gt; &lt;span class="c"&gt;# private key for personal
&lt;/span&gt;&lt;span class="err"&gt;IdentitiesOnly&lt;/span&gt;  &lt;span class="err"&gt;yes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;add ssh key to your github account. follow &lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account" rel="noopener noreferrer"&gt;add ssh to github&lt;/a&gt;. basically cat your personal key (make sure it is not accessible for all users, i had to revoke permission for all other users) and copy the content till last (with out carriage return) and paste it in GitHub.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;add both private keys to OpenSSH cache by running following command&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;ssh-add&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;\work_key&lt;/span&gt;&lt;span class="w"&gt; 
&lt;/span&gt;&lt;span class="n"&gt;ssh-add&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;\personal_key&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;confirm things are working so far by running&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;ssh&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Tv&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;per&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# for personal key (per is the alias)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;ssh&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Tv&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;work&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# for work key (work is the alias)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;if everything is correct so far, you will see the line below in the pile of lines&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hi anmjubaer! You've successfully authenticated, but GitHub does not provide shell access.
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;(in your case, your name)&lt;/p&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;next, go to your user folder. you may see a file named .gitconfig. if not, create one with content (with others if exists)&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[includeIf "gitdir:E:/work/"]&lt;/span&gt; &lt;span class="c"&gt;# maintain seperate work repo-parent folder (where all your work-related repositories will be located)
&lt;/span&gt;&lt;span class="py"&gt;path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;./.gitconfig-work&lt;/span&gt;

&lt;span class="nn"&gt;[includeIf "gitdir:E:/jb/"]&lt;/span&gt; &lt;span class="c"&gt;# maintain seperate personal repo-parent folder (where all your personal repositories will be located)
&lt;/span&gt;&lt;span class="py"&gt;path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;./.gitconfig-personal&lt;/span&gt;

&lt;span class="nn"&gt;[user]&lt;/span&gt;
&lt;span class="py"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;jubaerad&lt;/span&gt;
&lt;span class="py"&gt;email&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;jubaerad1@gmail.com&lt;/span&gt;

&lt;span class="nn"&gt;[core]&lt;/span&gt;
&lt;span class="py"&gt;sshCommand&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;C:/Windows/System32/OpenSSH/ssh.exe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;don't worry, we will create .gitconfig-personal and .gitconfig-work next&lt;/p&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;now create two more file named (.gitconfig-work and .gitconfig-personal if you want) with content&lt;/p&gt;

&lt;p&gt;for .gitconfig-work&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[user]
name = anmj
email = yourworkemail@email.blah
[core]
    sshCommand = "ssh -i ~/.ssh/work_key"
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;for .gitconfig-personal&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[user]
name = jubaerad
email = jubaerad1@gmail.com
[core]
    sshCommand = "ssh -i ~/.ssh/personal_key"
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;now clone or set remote starting with appropriate host alias. for example, instead of&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone git@github.com:jubaer-ad/GraphQLDemo.git
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;use&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone per:jubaer-ad/GraphQLDemo.git # remember? per is the alias we set earlier for personal usage
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;finally some words from Gemini 2.0 Flash (yes, i used it)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Boom! You've officially wrangled those SSH keys into submission. Now you can switch between GitHub accounts like a secret agent changing disguises. Just remember, with great SSH power comes great responsibility... like, don't accidentally push your personal cat meme collection to your work repo. We've all been there. (Or, at least, I've &lt;em&gt;heard&lt;/em&gt; someone has.) Happy coding, and may your pushes be swift and your merges be conflict-free (a developer can dream, right?)."&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
  </channel>
</rss>
