Add new comment

Setting up SSH Keys for more than one account and repository

Setting up SSH Keys for more than one account and repository

https://medium.com/@fredrikanderzon/setting-up-ssh-keys-for-multiple-bitbucket-github-accounts-a5244c28c0ac

 

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).

 

 

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.