Today I Learned

hashrocket A Hashrocket project

Connecting to github via ssh with different users

Due to github permissions on projects that I am working on I wanted to switch which user I am connecting to github on a per project base. I also want to keep using ssh keys for that, so I found out that we can have 2 different ssh keys pointint to the same domain, we just had to do a simple twich:

Host github.com
    HostName github.com
    IdentityFile ~/.ssh/id_ed25519

Host vinny.github.com
    HostName github.com
    IdentityFile ~/.ssh/vinny_id_ed25519

So I end up creating 2 ssh keys, 1 per user that I need to access on github. Then left the original ssh key as regular github.com domain, so no changes there, and on the projects that I need to access with the other user I had to clone with:

git clone git@vinny.github.com:MyOrganization/my-project.git

And if you have an exisintg project that you want to move to this new github user you'll have to change the remote on that:

git remote remove origin
git remote add origin git@vinny.github.com:MyOrganization/my-project.git

By the way, as you are changing which keys to use with an existing domain, you may have to restart the ssh-agent in order for this to work:

eval "$(ssh-agent -s)"
See More #git TILs