November 2013

Gavin Pickin

Git for Dummies - Creating your SSH Keys for Bit Bucket

Source Control

Many Git Servers communicate using SSH, and to authenticate, you should use SSH Keys. You can setup multiple keys, but that goes beyond a Dummies setup… so we'll setup a general Public / Private SSH Key Pair.  If you don't have a Bit Bucket account, make sure you go through this post. If you need to install Git on Windows, Mac OSX and Linux, visit some of my older posts.

To see a list of keys you currently have available, you change directory to .ssh and list the contents

$ cd ~/.ssh
$ ls

You might see a couple of files, but if you're new to SSH, you'll probably see the following, i.e.- just known_hosts

Now, we want to generate keys, so we enter

$ ssh-keygen

It will start generating the keys. First, it will prompt you for a name for your key, the default is "id_rsa", You can accept the default.
Next, it asks you for a password. If you are concerned about security on this machine, you can enter a password, or you can leave it blank, which is ideal for automation scripts, or for dummies and lazy people, so that's what I'll do.

Zip, zap, zoom, away it goes, and ta-da, you have generated your keys.

Once you have generated your keys, to use your private key, you need to make your public key, public… so if you don't have a Bit Bucket account, make sure you go through this post.

Once you login, you want to click on the Avatar in the far right corner, and click on Manage Account.

Once your Manage Account screen comes up, you need to look for SSH Keys on the left hand side. This is where you store your public key, so Bit Bucket can authenticate your machine, and let the machine with the right keys access repos on this account.

The SSH Keys Page lists all of your SSH keys asociated with this account... listed from newest first to oldest. This screenshot just shows the most recent key in my list.

Click Add Key to add the Key for your new Machine.
Give the Key a meaningful Label. Copy the contents of your file... and paste it into the Key field like below.

Click Add Key, and then you will see it is successfully listed in your SSH Key list.

Now each time we communicate from this machine, with a Bit Bucket Repo, we'll match our Private Key with Bit Buckets Public key for our account, and we'll be allowed access to any Repo our Bit Bucket User has access to.

So lets go back to the command line, and try it out.

$ git push -u origin --all

Sorry for the continuity here, its another repo, but showing how a successful push looks.

As you can see below, Git knows we want to push all of the branches, and we trust the server, and Bit Bucket uses the keys to authenticate us, and the push is successful.

Now we have keys setup, and we pushed our first repos... you probably are thinking to yourself, I don't want to start from scratch for every repo, what if I have websites and projects that already exist?
No problem, its not much different than starting from scratch, check back for that entry coming soon.

Blog Search