Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thekingofbandit/012521f37256510d361814329908ba8b to your computer and use it in GitHub Desktop.
Save thekingofbandit/012521f37256510d361814329908ba8b 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: [email protected]:<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 [email protected]:<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