<?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: M_S_360</title>
    <description>The latest articles on DEV Community by M_S_360 (@m_s_360).</description>
    <link>https://dev.to/m_s_360</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%2F646497%2Fce6b9c36-ebfc-4455-9e8b-4e74965c8c55.png</url>
      <title>DEV Community: M_S_360</title>
      <link>https://dev.to/m_s_360</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/m_s_360"/>
    <language>en</language>
    <item>
      <title>A Practical Guide to Managing Multiple Git Accounts with SSH</title>
      <dc:creator>M_S_360</dc:creator>
      <pubDate>Fri, 07 Nov 2025 20:07:02 +0000</pubDate>
      <link>https://dev.to/m_s_360/a-practical-guide-to-managing-multiple-git-accounts-with-ssh-3134</link>
      <guid>https://dev.to/m_s_360/a-practical-guide-to-managing-multiple-git-accounts-with-ssh-3134</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltrzqhjkdbly3fe9uxjb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltrzqhjkdbly3fe9uxjb.png" alt=" " width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you only have one account, using Git is easy—until you add more.&lt;br&gt;
Perhaps you organize coursework on Bitbucket, work with your team on GitLab, and contribute to open source on GitHub. All of a sudden, your Git IDs, SSH keys, and credentials begin to clash.&lt;/p&gt;

&lt;p&gt;From the straightforward scenario of one account to a complex multi-account configuration, this tutorial takes you step-by-step through the management of SSH keys and Git identities across several accounts.&lt;/p&gt;
&lt;h1&gt;
  
  
  The Simple Case: One Git Account
&lt;/h1&gt;

&lt;p&gt;If you only use one Git account, life is easy.&lt;/p&gt;
&lt;h3&gt;
  
  
  Generate an SSH key:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t ed25519 -C "you@example.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Add the key to your Git provider.
&lt;/h3&gt;

&lt;p&gt;Copy your public key and paste it in your account settings:&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/id_ed25519.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Test your connection:
&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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hi username! You've successfully authenticated.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With one account, Git will automatically use this single SSH key. You’re done.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Real World: Multiple Git Accounts
&lt;/h1&gt;

&lt;p&gt;Once you manage multiple accounts, things get complicated:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Personal GitHub for side projects&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Work Gitlab for company code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Another Work Github for another company project&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;School Bitbucket for academic repositories&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each service should have its own SSH key, so that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You avoid identity confusion (wrong commits under the wrong name)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Access permissions remain separate&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your personal and professional lives stay cleanly divided&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  First Step: Create Separate SSH Keys
&lt;/h1&gt;

&lt;p&gt;Let’s generate one SSH key per account:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Personal GitHub
ssh-keygen -t ed25519 -C "personal@example.com" -f ~/.ssh/id_ed25519_github

# Work GitLab
ssh-keygen -t ed25519 -C "work@example.com" -f ~/.ssh/id_ed25519_gitlab_work

# Another Work Github
ssh-keygen -t ed25519 -C "work2@example.com" -f ~/.ssh/id_ed25519_github_work


# School Bitbucket
ssh-keygen -t ed25519 -C "school@example.edu" -f ~/.ssh/id_ed25519_bitbucket
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll now have files like these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/.ssh/
├── id_ed25519_github
├── id_ed25519_github.pub
├── id_ed25519_gitlab_work
├── id_ed25519_gitlab_work.pub
├── id_ed25519_github_work
├── id_ed25519_github_work.pub
├── id_ed25519_bitbucket
└── id_ed25519_bitbucket.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add each public key (.pub file) to the matching Git account.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account#adding-a-new-ssh-key-to-your-account" rel="noopener noreferrer"&gt;Adding ssh key to Github&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.gitlab.com/user/ssh/#add-an-ssh-key-to-your-gitlab-account" rel="noopener noreferrer"&gt;Adding ssh key to Gitlab&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://support.atlassian.com/bitbucket-cloud/docs/set-up-personal-ssh-keys-on-linux/#Provide-Bitbucket-Cloud-with-your-public-key" rel="noopener noreferrer"&gt;Adding SSH key to Bitbucket&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Verifying that you can SSH into respective accounts
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -i ~/.ssh/id_ed25519_github git@github.com
ssh -i ~/.ssh/id_ed25519_gitlab_work git@gitlab.com
ssh -i ~/.ssh/id_ed25519_github_work git@github.com
ssh -i ~/.ssh/id_ed25519_bitbucket git@bitbucket.org
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, having to explicitly specify your ssh keys everytime is not particularly exciting and easy to forget.&lt;/p&gt;

&lt;h1&gt;
  
  
  Using ssh-agent: A Quick Way to Handle Multiple Keys
&lt;/h1&gt;

&lt;p&gt;That’s where ssh-agent helps — it securely stores your decrypted private keys in memory.&lt;/p&gt;

&lt;p&gt;Start the agent and add your keys:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_github
ssh-add ~/.ssh/id_ed25519_gitlab_work
ssh-add ~/.ssh/id_ed25519_github_work
ssh-add ~/.ssh/id_ed25519_bitbucket
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check that your keys are loaded:&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;p&gt;Now you can connect to your repositories without re-entering passwords every time.&lt;/p&gt;

&lt;p&gt;However, the ssh-agent only runs for your current login or terminal session.&lt;br&gt;
If you restart your system, log out, or even open a new terminal, the agent may not remember your loaded keys.&lt;br&gt;
You’ll need to re-run the following code everytime you start a terminal session:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_github
# further run ssh-add for every other keys we generated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(On Linux) To make it persistent, you can use a desktop keyring manager (like &lt;a href="https://wiki.archlinux.org/title/GNOME/Keyring" rel="noopener noreferrer"&gt;gnome-keyring&lt;/a&gt;), or configure your shell startup files (~/.bashrc, ~/.zshrc) to start and load your keys automatically.&lt;/p&gt;

&lt;h1&gt;
  
  
  Automate Key Selection with SSH Config (The Savior Step)
&lt;/h1&gt;

&lt;p&gt;Create &lt;code&gt;~/.ssh/config&lt;/code&gt; file (if not already present) or add the following entries to it (if it already exists):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Personal GitHub
Host github.com-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_github
  IdentitiesOnly yes


# Work GitLab
Host gitlab.com-work
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_ed25519_gitlab_work
  IdentitiesOnly yes


# Work Github
Host github.com-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_github_work
  IdentitiesOnly yes


# School Bitbucket
Host bitbucket.org-school
  HostName bitbucket.org
  User git
  IdentityFile ~/.ssh/id_ed25519_bitbucket
  IdentitiesOnly yes

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, use the aliases when cloning repositories, as per defined in your &lt;code&gt;~/.ssh/config&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Personal
git clone git@github.com-personal:username/personal-repo.git

# Work Gitlab
git clone git@gitlab.com-work:company/work-gitlab-repo.git

# Work Github
git clone git@github.com-work:company/work-github-repo.git


# School
git clone git@bitbucket.org-school:university/coursework.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can clone, pull and push your changes to Git Hosting Platforms without worrying about specifying the ssh private key explicitly or starting &lt;code&gt;ssh-agent&lt;/code&gt; on every terminal session.&lt;/p&gt;

&lt;h1&gt;
  
  
  Bonus Tip
&lt;/h1&gt;

&lt;p&gt;Always configure your Git username and email before making any commits — it saves you from headaches later. After cloning a repository, set your local username and email with the following commands:&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 --local user.name "your_name"
git config --local user.email "your_email"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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