Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jbutko/eab260183292e31148ff393b5e8dd863 to your computer and use it in GitHub Desktop.
Save jbutko/eab260183292e31148ff393b5e8dd863 to your computer and use it in GitHub Desktop.
How to set up two SSH keys for two GitLab accounts

Simply declare each private ssh keys in a %HOME%/.ssh/config file:

Host gitlabuser1
    User git
    Hostname {hostname}
    PreferredAuthentications publickey
    IdentityFile C:/Users/{username}/.ssh/id_rsa1

Host gitlabuser2
    User git
    Hostname {hostname}
    PreferredAuthentications publickey
    IdentityFile C:/Users/{username}/.ssh/id_rsa2

That supposes your set of ssh keys are:

%HOME%/.ssh/id_rsa1 ; %HOME%/.ssh/id_rsa1.pub
%HOME%/.ssh/id_rsa2 ; %HOME%/.ssh/id_rsa2.pub

You can then use the urls for clone/push/pull:

gitlabuser1:yourRepo1
gitlabuser2:yourRepo2

Note: You need to edit remote repo in .git/config based on value from ./.ssh/config

via https://stackoverflow.com/questions/30320458/how-to-set-up-two-ssh-keys-for-two-gitlab-accounts-and-push-pull-by-using-tortoi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment