Skip to content

Instantly share code, notes, and snippets.

@suceda
Last active November 28, 2020 19:40
Show Gist options
  • Select an option

  • Save suceda/6ad3528d376a264695bb250daa3fd374 to your computer and use it in GitHub Desktop.

Select an option

Save suceda/6ad3528d376a264695bb250daa3fd374 to your computer and use it in GitHub Desktop.
Multiple Github accounts on a single machine (On Mac)

Multiple Github accounts on a single machine (On Mac)

Create different public keys (for example, personal and work)

Generating new SSH key (link)

$ ssh-keygen -t ed25519 -C "your_email@example.com"

For example:

~/.ssh/id_ed25519
~/.ssh/id_ed25519_work

Then add the keys to the ssh agent:

$ ssh-add ~/.ssh/id_ed25519
$ ssh-add ~/.ssh/id_ed25519_work

Add your ssh keys to your github accounts

https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account

Create the SSH config file

Edit the SSH config file:

$ vim ~/.ssh/config

Should be similar to the one below:

# Personal account (default config)
Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_ed25519
   
# Work account
Host github.com-work    
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_ed25519_work

Examples

Cloning a new repo for your work github account:

$ git clone git@github.com-work:your-username/repo-name.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment