How to Manage Multiple SSH Keys for GitHub, GitLab, etc.

Karolis Šarapnickis
1 min readSep 12, 2021

Short tutorial on how to structure projects and setup multi-user Git SSH workflow.

When using a single machine with multiple git accounts, you might encounter some obstacles with SSH setup. The easiest way to achieve a multi-user setup is to structure git repositories by respective directories, e.g.:

This short tutorial will help you set up SHH for such workflow.

Generating a new SSH key

To generate a new SSH key, use the provided template script (or check the docs):

What’s left is to add the SSH key to your GitHub/GitLab/etc. account.

Multi-user Git SSH setup

The general idea is that you use specific ssh command based on your working directory with the help of git includes.

Update the ~/.gitconfig file:

And the ~/.gitconfig.work file:

And that’s it! Appropriate SSH setup will be used based on directory location, no extra actions are needed.

--

--