associate ssh key with git remote host

I often run into to issues where I like to use different ssh keys for different sites, servers, and other things.  It is a good practice not to use the same key for everything just in case you need to change it, or other various reasons.  If you are like me and don’t want to manually enter the path to theses keys each time you can associate them with a url.  So if you were connecting via ssh, or over git with ssh it works perfectly.

So first generate a key.  In this example we will create one for Bit Bucket.

ssh-keygen -f ~/.ssh/bitbucket

Now inside the ~/.ssh folder edit the config file and add the text below.

IdentityFile ~/.ssh/bitbucket
IdentitiesOnly yes

At this point when you push to bitbucket it will use this key.. For example if you added the remote repo as origin

git push origin master

It should prompt you for your ssh unlock pass phrase.

Published by

Ryein C. Goddard

I'm a programmer, auto hobbyist, gardener, father, futurist and Linux enthusiast. I really like PHP for web development using laravel. For desktop/mobile development I like Qt. I also use Python for desktop scripting tasks. I am from the United States and currently live in South East Georgia, or better known as the Florida Georgia line.