Created
January 7, 2022 15:17
-
-
Save antonga23/c0fdfbdb934e4287c839ce1fc9e1bcad to your computer and use it in GitHub Desktop.
A simple way to authenticate to github using ssh across multiple accounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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