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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 2
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 1
  • CI/CD Integration: Running Playwright on GitHub Actions: The Definitive Automation Blueprint
  • Chat with Your Oracle Database: SQLcl MCP + GitHub Copilot

Trending

  • 7 Technology Waves I’ve Seen in 30 Years of Software — Will AI Be the Next Real Transformation?
  • Getting Started With Agentic Workflows in Java and Quarkus
  • DZone's Article Submission Guidelines
  • How to Submit a Post to DZone
  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 user avatar
Sushant Mimani
·
Aug. 23, 23 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
69.5K Views

Join the DZone community and get the full member experience.

Join For Free

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

  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 2
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 1
  • CI/CD Integration: Running Playwright on GitHub Actions: The Definitive Automation Blueprint
  • Chat with Your Oracle Database: SQLcl MCP + GitHub Copilot

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • 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