DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Containerizing and Testing a Python Backtesting System With Docker and GitHub Actions
  • Architectural Collapse: How Extension Poisoning, Node Vulnerabilities, and Infrastructure Fog Enabled the GitHub Repository Breach
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 2
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 1

Trending

  • Building an AI-Powered Code Review Assistant in Java
  • Running an OpenStreetMap Tile Server for the Whole Planet on Modest Hardware
  • Using Middleware in LangChain: Recovering From Tool Failures
  • When Jev Says It's Sure, Is It Right? A Fraud Case Study in Neo4j

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Mastering Multiple GitHub Accounts

Mastering Multiple GitHub Accounts

In this article, we'll explore how to leverage this configuration file to set up seamless access to multiple GitHub accounts simultaneously.

By 
Sushant Mimani
·
Aug. 23, 23 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
69.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Managing multiple GitHub accounts can be a daunting task, especially for developers who work on personal and professional projects across different organizations. Manually switching between accounts every time you want to push code can lead to confusion and potential errors. Thankfully, there’s a powerful solution — the ~/.ssh/config file. In this blog post, we'll explore how to leverage this configuration file to set up seamless access to multiple GitHub accounts simultaneously. By the end, you'll be empowered to effortlessly navigate between your various accounts, streamlining your development workflow.

Understanding ~/.ssh/config

The ~/.ssh/config file is a hidden configuration file located in the user's home directory. It allows you to define custom configurations for SSH connections, including those to GitHub repositories. By setting up specific rules for each GitHub account, you can automatically switch between accounts without the need for manual configurations.

Configuring Multiple GitHub Accounts

Step 1: Backup Existing SSH Configurations

Before making any changes, it’s essential to back up your existing ~/.ssh/config file. This ensures that you can easily revert to your original settings if needed.

Step 2: Generate SSH Key Pairs for Each Account

For each GitHub account you want to access, you’ll need to generate a separate SSH key pair. This can be done using the ssh-keygen command. Be sure to name each key pair uniquely, corresponding to the associated GitHub account.

Step 3: Edit ~/.ssh/config

# Personal GitHub account
Host github.com-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_personal

# Work GitHub account
Host github.com-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_work


Replace id_rsa_personal and id_rsa_work with the file paths of the SSH private keys you generated for your personal and work GitHub accounts, respectively.

Step 4: Configure/Clone Your Repositories

For any cloned repository you want to access, update the remote URL in the repository’s .git/config file. For example:

[remote "origin"]
  url = [email protected]:YourUsername/YourRepo.git


Replace YourUsername and YourRepo with your personal GitHub account's username and the repository name, respectively. Repeat this process for other repositories.

For cloning new repositories, simply use the appropriate suffix:

git clone [email protected]:YourUsername/YourRepo.git
git clone [email protected]:WorkOrg/WorkRepo.git


Conclusion

Leveraging the power of ~/.ssh/config to manage multiple GitHub accounts can significantly enhance your development experience. With this simple yet powerful configuration, you can seamlessly switch between accounts, ensuring a smooth and error-free workflow. Embrace the convenience of managing multiple GitHub accounts effortlessly, and watch your productivity soar to new heights. Happy coding!

Resources

Creating a new ssh key

Adding an ssh key to GitHub

GitHub

Published at DZone with permission of Sushant Mimani. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Containerizing and Testing a Python Backtesting System With Docker and GitHub Actions
  • Architectural Collapse: How Extension Poisoning, Node Vulnerabilities, and Infrastructure Fog Enabled the GitHub Repository Breach
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 2
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 1

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook