Skip to content

Instantly share code, notes, and snippets.

@bangn
Last active March 29, 2020 22:08
Show Gist options
  • Save bangn/13cfbf22f158f5717733857073331c7b to your computer and use it in GitHub Desktop.
Save bangn/13cfbf22f158f5717733857073331c7b to your computer and use it in GitHub Desktop.
Using multiple SSH keys for different account/group

Using multiple SSH keys

Update ssh config

# Personal github
host github-personal
  HostName github.com
  Port 22
  AddKeysToAgent yes
  IdentityFile ~/.ssh/personal_id_rsa

# Work github
host github-work
  HostName github.com
  Port 22
  AddKeysToAgent yes
  IdentityFile ~/.ssh/work_id_rsa

Clone repo

git clone git@github-{personal,work}:user/repo.git

SSH key may need to be added to ssh-agent first

ssh-add /path/to/private/ssh-key

Update git remote origin config

[remote "origin"]
  url = git@github-{personal,work}:user/repo.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment