Using multiple RSA keys to connect through SSH

I was just having trouble because you can’t use the same RSA key in order to connect to multiple accounts on bitbucket, this can be solved creating a new one, but you need to know how to handle them, and there is two ways to do it.

If you just need to connect with ssh to a host well you can just put it as a parameter, but this doesn’t work as a complete solution.


This problem can be solved using a config file, for this solution you just need to create a file ~/.ssh/config and

Host shortname
    IdentityFile ~/.ssh/realname_rsa
    User remoteusername

Host bitbucket_1
    IdentityFile ~/.ssh/account1_rsa
    User git

Host bitbucket_2
    IdentityFile ~/.ssh/account2_rsa
    User git

This way you could make, for example a clone in the following way:

git clone git@bitbucket_1:user/repo.git
git clone git@bitbucket_2:otheruser/repo.git

And it works just fine with your multiple accounts.

Note: Keep in mind that according to that configuration, because two hosts share the same alias if you clone from the real url, meaning it will use the later, in this case account_2 for the authentication. (You can obviously erase it from the Host tag, but this is just to explain the case)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s