You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You should now be able to manage two GitHub accounts using SSH without any issues! Each account will use the appropriate SSH key when you clone or push to repositories.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Step 1: Generate SSH Keys
Open your terminal.
Generate a new SSH key for each GitHub account. Replace
[email protected]
with your email associated with each GitHub account.For the first account:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
When prompted to save the key, give it a unique name (e.g.,
id_rsa_github_personal
):For the second account:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Save this key with another unique name (e.g.,
id_rsa_github_work
):Step 2: Add SSH Keys to the SSH Agent
Start the SSH agent:
Add your SSH keys:
Step 3: Add SSH Keys to Your GitHub Accounts
Copy the SSH key to your clipboard:
cat ~/.ssh/id_rsa_github_personal.pub
Go to GitHub (for the first account) > Settings > SSH and GPG keys > New SSH key. Paste the key and save.
Repeat the process for the second account:
cat ~/.ssh/id_rsa_github_work.pub
Add this key to the second GitHub account in the same way.
Step 4: Configure SSH Config File
Open (or create) the SSH config file:
nano ~/.ssh/config
Add configurations for both accounts:
Step 5: Clone Repositories Using the Correct Host
When cloning repositories, use the corresponding host defined in your SSH config:
For the personal account:
For the work account:
Conclusion
You should now be able to manage two GitHub accounts using SSH without any issues! Each account will use the appropriate SSH key when you clone or push to repositories.
Beta Was this translation helpful? Give feedback.
All reactions