Skip to content

Instantly share code, notes, and snippets.

@aadshalshihry
Last active August 21, 2019 09:18
Show Gist options
  • Save aadshalshihry/0da440b00c7223086eedbca3a15ffc7f to your computer and use it in GitHub Desktop.
Save aadshalshihry/0da440b00c7223086eedbca3a15ffc7f to your computer and use it in GitHub Desktop.
How to setup two Git Account in one machine using ssh key

Create to two ssh-key

Generate two keys

  # this is the main email to be use with github
  # filename: ~/.ssh/rsa_id
  ssh-keygen -t rsa -f ~/.ssh/id_rsa -b 4096 -C "1stEmail@example.com"
  
  # this is the main email to be use with github
  # filename: ~/.ssh/rsa_id_othername
  ssh-keygen -t rsa -f ~/.ssh/id_rsa_othername -b 4096 -C "2ndEmail@example.com"

Create ~/.ssh/config file to manage both keys

Add the following to ~/.ssh/config

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa


Host github-othername
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_othername

Setup github to work with both keys

Add the folloing to folder-location/.git/config

[remote "origin"]
        url = git@github-othername:username/reponame.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment