How to setup multiple git account in a single computer:

I want to use multiple GitLab (or GitHub, etc.) on my machine. One could be your personal account and another one you use specifically for my startup ideas. I want to use different SSH keys to access the repositories in either account.

Here’s how to achieve that setup properly. Let’s assume we have the two GitLab accounts:

Generate ssh keys for both profile:

ssh-keygen -t rsa -b 2048 -C "personal" - name the key: personal_key
ssh-keygen -t rsa -b 2048 -C "startup" - name the key: startup_key

Configure SSH to use the correct keys:

Now create the file ~/.ssh/config and add the following contents:

Host gitlab.com
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/personal_key
Host gitlab.com-startup
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/startup_key