Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nextuponstream/cbfb45ee2b54a4569eca3084eb1ac90b to your computer and use it in GitHub Desktop.
Save nextuponstream/cbfb45ee2b54a4569eca3084eb1ac90b to your computer and use it in GitHub Desktop.
configure multiple github accounts on the same machine.md

SSH keys

Create

ssh-keygen -o

You can view the created files (one without extension and one with .pub) under ~/.ssh/. When creating several of them, you may want to rename them appropriately (e.g. work, pers...).

Add them

to the relevant github account: https://github.com/settings/ssh/new

Configuration

The configuration file for ssh is usually not created by default so we create it:

touch ~/.ssh/config

Now paste in the config file the following:

# work account
 Host work.github.com
 HostName github.com
 User git
 IdentityFile ~/.ssh/work

 # personnal account
 Host pers.github.com
 HostName github.com
 User git
 IdentityFile ~/.ssh/pers

Usage

Usually, the ssh clone url looks like this: git@github.com:<account>/<project>.git

To link the right ssh key, prepend to <account> either pers. or work depending on who should be committing. This results in the following git clone command:

git clone git@work.github.com:<account>/<project>.git

Now you can commit as you want and work on your cloned project with the right user.

Next steps

  • what is keychain parameter in config file
  • why is the commit user kinda ugly looking in github when looking at the commit history?

Credit

https://www.freecodecamp.org/news/manage-multiple-github-accounts-the-ssh-way-2dadc30ccaca/

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