69902.9 / 08 June 2016

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.

1
ssh-keygen -f ~/.ssh/bitbucket

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

1
2
3
Host bitbucket.org
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

1
git push origin master

It should prompt you for your ssh unlock pass phrase.