Joan Antoni Morey
3 min
05/03/2023
Have you had to use a second Github account to clone a repository and have been unable to do so? As you may have noticed, it's not as simple as doing a git clone of the new repository and you're done. In this case, you will need to do a small configuration of the "config" file in the ".ssh" folder.
If you only use one Github account, you probably never have to modify that file because you will use the default configuration. The problem arises when you need to use another Github account and perform any action with that account on a repository (clone, pull, push...), either because a client has provided you with another account for their project, or because you are a student and your school or university has provided you with student credentials on Github, or simply because you have just created another Github account for whatever reason.
What do we do in case this happens? First, we need to generate our SSH keys, upload them to Github, and add them to our ".ssh" folder.
Assuming you already have your SSH keys for both Github accounts, let's configure them! In the following example, let's suppose you have a personal and a work account that you need to use on the same machine. Here are the steps to follow in order to use both:
# Personal Github account
Host github.com
HostName github.com
User your_personal_github_username
IdentityFile ~/.ssh/id_rsa_personal
# Work Github account
Host github-work
HostName github.com
User your_work_github_username
IdentityFile ~/.ssh/id_rsa_work
git clone git@github.com:personal_username/repository_name.git
git clone git@github-work:work_username/repository_name.git
Remember to use the "github-work" address for the work account instead of "github.com".
With these steps, you can now use both of your Github accounts on the same machine. Configuring two Github accounts may seem a bit complicated at first, but with the right steps and correct information, it's easy to do. Don't get discouraged if it takes you a little time to understand the process. Remember... practice makes perfection.