Code Notes

A quick note on SSH and Bitbucket

Bitbucket's ssh setup/guides are pretty terrible. This is a widely known fact. They switch between git and mercurial without even a mention. If you're new to this whole game, it can throw you for a loop. Or two or three hours worth of loops and web searching for answers.

If you're like many people, you have a personal account and a work account, multiple keys, but still have problems connecting via ssh.

Step 1. If you haven't already, generate a second key with a different file-name, and add each of the public keys to your bitbucket account.

Use: ssh-keygen -t rsa to start the key generation process

Then use: cat ~/.ssh/ to show the public key in the terminal. Copy this whole thing and paste it into the appropriate spot in bitbucket.

Step 2. Set up your .ssh/config file to use which particular key for each project.

eg. in my .ssh/config file, I have two entries that identity which key to use

User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

Host digitaloid
User git
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/digitaloid

Step 3. Set up your .git/config file to use those host ssh configuration

In the .git/config file for your project, edit your bitbucketURL from the https:// link to one that matches the following formula:

ssh:// [ host ] / [ username ] / [repository]

eg. for my diamondpriceinfo project, I have the digitaloid hostname set up, with my wakingideas username, and the diamondpriceinfo git repo

[remote "origin"]
url = ssh://digitaloid/wakingideas/diamondpriceinfo.git
fetch = +refs/heads/*:refs/remotes/origin/*

That's it! The next time you do a git-pull, it will ask to update/add new entries to your known_hosts file, and then you'll be all set.