English
Français

Blog of Denis VOITURON

for a better .NET world

Multiple SSH accounts in GitHub

Posted on 2022-12-19

When working with GitHub (or GIT), you may need to use multiple accounts on the same computer. This article describes how to create and use multiple SSH keys in order to work on multiple repositories, from the same PC.

First of all, you need to install the GIT tools for Windows.

Create SSH keys

The first step is to create the SSH keys, from the C:\Users\[UserName]\.ssh folder. Two files will be generated for each commands (ex. perso-id_rsa and perso-id_rsa.pub).

ssh-keygen -f perso-id_rsa
ssh-keygen -f work-id_rsa

Create SSH

Display the public key, present in the .pub file (using Notpad, for example). You have to copy all this content in GitHub, section Settings / SSH and GPG Keys / SSH keys.

Add key in GitHub

Create the configuration file

In the same .ssh folder, use notepad to create a config file (without extension). This file will contain the definition of the two accounts: personal (perso) and work. If the .ssh folder does not exist, you can create it.

# Account 1
Host github.com-perso
 HostName github.com
 IdentityFile ~/.ssh/perso-id_rsa

# Account 2
Host github.com-work
 HostName github.com
 IdentityFile ~/.ssh/work-id_rsa

Closing your repos

Now that these configurations are saved, you can open your terminal in your repository folder and use the following command.

If you copy/paste the Clone command from the GitHub site (as shown below), you need to replace git@github.com: with git@github.com-perso:. This corresponds to the Host value in your configuration file.

git clone git@github.com-perso:dvoituron/temperature-wasm.git
                        ^^^^^^

⚠️ When cloning the repository, you will probably have to accept the command by answering yes.

Clone a repo

Languages

EnglishEnglish
FrenchFrançais

Follow me

Recent posts