
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! π₯
Table of Contents
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
- Copy the output.
- Go to GitHub β Settings β SSH and GPG keys.
- 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! ππ¨βπ»π©βπ»