I have created two GitHub accounts. One for my work user and one for my personal self. I needed to do catch up on some work and as such cloned my work repo onto my personal PC
I've found a workaround that works for me:
You cannot add the same SSH key to different accounts, and that is true for GitHub, BitBucket, etc. But you can use different SSH keys for each account. The only downside then is how to easily switch between them?
I use ssh-agent
and it can use multiple keys at the same time. I auto add them through .bashrc
if [ -z "$SSH_AUTH_SOCK" ] ; then
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa2
fi
This approach works regardless of which key is added in your GitHub account. I guess ssh-agent
makes attempts with each key until it succeeds. And if you don't want to add all keys, you just comment out the relevant line in the .bashrc
before starting a new shell.