How to use multiple GitHub accounts on one machine
Quick tutorial on how to use multiple GitHub accounts on one machine with SSH keys
I needed to create a new GitHub account for work, but I didn't want to switch my credentials every time I pushed, cloned, or pulled from my private repositories.
I quickly googled how to achieve this without much hassle, and here it is:
1. Generate the SSH keys for both your work and private emails.
It will ask you to enter a unique file name and passphrase. I liked the file name pattern from the other blog post, so I borrowed (stole) it
id_rsa_personal
andid_rsa_work
Don't forget to save the passphrase somewhere safe! For example in 1password.
I am not sure if you should keep the commands' output, but I did! Just in case!
2. Copy the SSH keys and paste them into the appropriate GitHub account
Log in to the appropriate GitHub account, go to settings. Click on the SSH and GPG keys
, and paste one of the ssh keys.
3. Setup SSH config
You need to create an SSH config with both hosts configured.
4. Add the SSH keys to the SSH Agent
5. Clone the repository to test things out
Source: https://www.section.io/engineering-education/using-multiple-ssh-keys-for-multiple-github-accounts/
Published on July 23, 2022 • 2 min read