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

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.

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.

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.

--

--

Senior Software Engineering

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store