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
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Best GitHub-Like Alternatives for Machine Learning Projects
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • Continuous Integration for iOS and macOS
  • GraalVM Features and Future

Trending

  • Creating a High-Performance DevOps Toolchain
  • AWS Amplify: A Comprehensive Guide
  • What Is a Flaky Test?
  • Microservices With Apache Camel and Quarkus
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Mastering Multiple GitHub Accounts

Mastering Multiple GitHub Accounts

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

Sushant Mimani user avatar by
Sushant Mimani
·
Aug. 23, 23 · Tutorial
Like (2)
Save
Tweet
Share
21.88K 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

  • Best GitHub-Like Alternatives for Machine Learning Projects
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • Continuous Integration for iOS and macOS
  • GraalVM Features and Future

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • 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: