Skip to content

Instantly share code, notes, and snippets.

@antonga23
Created January 7, 2022 15:17
Show Gist options
  • Save antonga23/c0fdfbdb934e4287c839ce1fc9e1bcad to your computer and use it in GitHub Desktop.
Save antonga23/c0fdfbdb934e4287c839ce1fc9e1bcad to your computer and use it in GitHub Desktop.
A simple way to authenticate to github using ssh across multiple accounts
1. Generate keys for github accounts
eg.
ssh-keygen -t ed25519 -C "[email protected]"
ssh-keygen -t ed25519 -C "[email protected]"
2. Start ssh-agent in background and add keys
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/path_to_key1
ssh-add ~/.ssh/path_to_key2
3. Add ssh key to github, by pasting the *public* key to the browser
4. Modify ssh config file: .ssh/config
Host github.com
User git
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/INSERT_PRIVATE_KEY1
Host github-INSERT_NAME.com
User git
Hostname github.com
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/INSERT_PRIVATE_KEY2
git clone [email protected]:username/repo.git
git clone git@github-INSERT_NAME.com:username/repo.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment