Setting up SSH Keys for more than one account and repository
Setting up SSH Keys for more than one account and repository
My origins delving into git was creating an account on Bitbucket. That process was quite painless, learning how to create an SSH key on my laptop, setting it up for my account on Bitbucket.
Since becoming a Drupal intern it became necessary to connect to another repository, Pantheon, and also to connect to Bitbucket using a different account. Trying to do this I became thoroughly frustrated because in order to connect to these different systems I kept running into issues with duplicate keys, disconnected accounts, being able to get one to work but not the others.
I found a way to make it possible to have distinct accounts and SSH keys that will exist in harmony, without fear of duplicate keys or incompatible accounts.
First create a key for each instance needed and name it accordingly:
ssh-keygen -t rsa -C "companyName" -f "companyName"
ssh-add ~/.ssh/companyName
Create the SSH config file:
nano ~/.ssh/config
Edit the config file adding your individual instances:
Host companyname.bitbucket.org
HostName bitbucket.org
Username <your username>
IdentityFile ~/.ssh/companyName
Host github.com
HostName github.com
Username <your username>
IdentityFile ~/.ssh/id_rsa
Host AnyOldRepository
HostName github.com
Username <your username>
IdentityFile ~/.ssh/companyName
Now that the keys are setup you can go to your hosting repository and setup the key for that particular repository/username pair (follow the instructions for the individual repository).
Add new comment