Dynamic-Mess.com


"The world is a dynamic mess of jiggling things..."

How to use multiple SSH keys when working with different github repositories

Topic posted the 2023-03-23 in the category Développement

Topic updated: 2023-03-23

A very small tutorial how to use multiple SSH keys when working on different Github repositories.

Sometimes you might want to have multiple SSH keys on the same computer while working with multiple Github repositories. There might be many reasons, for instance security policies, and having a SSH key for your personal work and another one for your professional one. Let's focus on this example, and let's go.

The context

Setting the SSH configuration

Let's edit your ~/.ssh/config file and add the following:

Host gh-john
  User git
  Hostname github.com
  IdentityFile ~/.ssh/id_rsa_john

Here we defined a specific host to handle your personal key.

Cloning a repository

Let's assume you want to clone my GMG repository. If you want to use your professional key, just use the standard procedure to clone the repository locally:

git clone git@github.com:ecourtial/gmg.git .

But if you want to use your personal one, do this :

git clone gh-john:ecourtial/gmg.git .

Changing the email to sign your commits

If working on a personal project, edit the .git/config file at the project level, and add the following:

[user]
  name = John Doe
  email = myPersonalEmailAddress@bar.com

That's it!

 

 

 

 


Cet article vous a plu? Découvrez d'autres articles :


comments powered by Disqus