How to Use Multiple GitHub Accounts on Windows 11 Using SSH

How to Use Multiple GitHub Accounts on Windows 11 Using SSH

If you're a freelancer or a developer working with multiple clients, you might need to manage different GitHub accounts on your Windows 11 system. But how do you switch between them easily without getting into a login/logout mess? πŸ€”

The solution is SSH keys! πŸŽ‰ This guide will walk you through the process of setting up multiple GitHub accounts on Windows 11 using SSH in a simple and easy way. Let’s get started! πŸ”₯

Step 1: Generate SSH Keys for new Account

Run the following command (replace your_email@example.com with your GitHub email):

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • When prompted, enter a unique filename like id_rsa_client.
  • Leave the passphrase empty (or set one if you want extra security).

After entering the passphrase, the key is stored in the designated location, generating two files as shown below.

Now, you have two SSH keys: πŸ“Œ id_rsa (for your main GitHub account) πŸ“Œ id_rsa_client (for the new client’s GitHub account)

 Make sure not to overwrite the existing key for your default personal account. When prompted, save the file with a unique name, such as id_rsa_COMPANY.

One file is the public key, and the other is the private key. You'll need this key to connect with your GitHub account. To view its contents, use the following command.

cat .ssh/id_rsa_work.pub

Make sure to copy and save the key in a text file on your computer, as it will be required for adding it to your second GitHub account.

Step 4: Add SSH Keys to GitHub Accounts

Copy the SSH key:

cat ~/.ssh/id_rsa_client.pub
  1. Copy the output.
  2. Go to GitHub β†’ Settings β†’ SSH and GPG keys.
  3. Click New SSH Key, paste the key, and save.

Step 5: Configure SSH Config File

Now, let’s set up an SSH config file to manage the accounts smoothly.

Open Git Bash and run:

nano ~/.ssh/config

Add the following lines:

# Default GitHub Account
Host github.com-main
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa

# Client GitHub Account
Host github.com-client
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_client

Step 6: Clone Repositories Using Different Accounts

Now, when cloning repositories, use the appropriate Host name.

βœ… Clone a Repo Using Your Main Account:

git clone git@github.com-main:your-username/repo-name.git

βœ… Clone a Repo Using the Client Account:

git clone git@github.com-client:client-username/repo-name.git

For pushing code, Git will automatically use the correct SSH key. 🎯

Conclusion

That’s it! You have successfully set up multiple GitHub accounts on Windows 11 using SSH. Now, you can seamlessly switch between accounts without logging in and out all the time. πŸš€

If you found this guide helpful, don’t forget to share it with your developer friends! Happy coding! πŸŽ‰πŸ‘¨β€πŸ’»πŸ‘©β€πŸ’»

Subscribe to our Newsletter

Stay up to date! Get all the latest posts delivered straight to your inbox.

If You Appreciate What We Do Here On TutsCoder, You Should Consider:

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Leave a Comment