associate ssh key with git remote host

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.

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

git push origin master

It should prompt you for your ssh unlock pass phrase.

Comments are closed.