Configure Multiple GitHub Accounts on a Single Computer
Learn how to configure and manage multiple GitHub accounts on a single computer using SSH keys and Git configurations.
Here are step-by-step instructions for configuring and managing multiple GitHub accounts on a single computer, including SSH key setup and Git configuration:
Step 1: Generate SSH Keys for Each GitHub Account
-
Open your terminal.
-
Generate a new SSH key for the first GitHub account:
When prompted, save the key with a unique name, e.g.,
id_rsa_first_account
. -
Generate a new SSH key for the second GitHub account:
When prompted, save the key with a unique name, e.g.,
id_rsa_second_account
.
Step 2: Add SSH Keys to the SSH Agent
-
Start the SSH agent in the background:
-
Add the first SSH key to the SSH agent:
-
Add the second SSH key to the SSH agent:
Step 3: Add SSH Keys to GitHub Accounts
-
Copy the SSH key for the first account to your clipboard:
If
pbcopy
is not available, you can use: -
Log in to your first GitHub account and navigate to Settings > SSH and GPG keys > New SSH key. Paste the key and save.
-
Repeat the process for the second account:
If
pbcopy
is not available, you can use: -
Log in to your second GitHub account and navigate to Settings > SSH and GPG keys > New SSH key. Paste the key and save.
Step 4: Configure SSH to Manage Multiple Accounts
-
Edit the SSH config file:
-
Add the following configurations:
Step 5: Configure Git for Multiple Accounts
-
Set global Git configuration (if not already set):
-
For repositories associated with the first account, set the local Git configuration:
-
For repositories associated with the second account, set the local Git configuration:
Step 6: Clone Repositories Using the Correct SSH Host
-
For the first GitHub account, use:
-
For the second GitHub account, use:
Step 7: Push and Pull Using the Correct SSH Host
Git will automatically use the correct SSH key based on the configuration in the ~/.ssh/config
file.
That’s it! You have now configured and can manage multiple GitHub accounts on a single computer.