git ssh configuration with multiple accounts en

Just a quick thing to configure git with ssh when you have multiple accounts.

First, read how to create an SSH key on GitHub and Gitlab.

Let's say we have 2 keys:

  • One for home: ~/.ssh/home and ~/.ssh/home.pub
  • One for work: ~/.ssh/work and ~/.ssh/work.pub

Update the ssh configuration at ~/.ssh/config:

Host github.com
  HostName github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/home

Host github-work.com
  HostName github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/work

Then, to clone beulogue with (notice the hostname change !):

The home key, use:

git clone git@github.com:SiegfriedEhret/beulogue.git.

The work key, use:

git clone git@github-work.com:SiegfriedEhret/beulogue.git

See you !