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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Code Reviews: Building an AI-Powered GitHub Integration
  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • Concourse CI/CD Pipeline: Webhook Triggers
  • Build a Stateless Microservice With GitHub Copilot in VSCode

Trending

  • How to Merge HTML Documents in Java
  • Building an AI/ML Data Lake With Apache Iceberg
  • Monolith: The Good, The Bad and The Ugly
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 1
  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.2K 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 = git@github.com-personal: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 git@github.com-personal:YourUsername/YourRepo.git
git clone git@github.com-work: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

  • Code Reviews: Building an AI-Powered GitHub Integration
  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • Concourse CI/CD Pipeline: Webhook Triggers
  • Build a Stateless Microservice With GitHub Copilot in VSCode

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!