This guide applies to you if:
-
You use SSH authentication for git
-
You use more than one account, and thus require more than one SSH key in your ssh configuration file
# Generate key pair for Account 1
ssh-keygen -t ed25519 -C "[email protected]"
# Save it as ~/.ssh/id_ed25519_account1
# Generate key pair for Account 2
ssh-keygen -t ed25519 -C "[email protected]"
# Save it as ~/.ssh/id_ed25519_account2
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
# add keys to agent
ssh-add ~/.ssh/id_ed25519_account1
ssh-add ~/.ssh/id_ed25519_account2
Edit your SSH config file (typically ~/.ssh/config
) and add entries for both keys
# Account 1
Host github.com-account1
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_account1
# Account 2
Host github.com-account2
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_account2
Each time you clone a new repository, you need to pick which account to use with either:
git remote set-url origin [email protected]:<username>/<repository-name>.git
or
git remote set-url origin [email protected]:<username>/<repository-name>.git
...replacing <username>
with the github username and <repository-name>
with the name of the repository.