Friday 21 July 2017

Setting up SSH for BitBucket on Windows

Back to basics for me today. I’m rebuilding a machine and want to setup SSH to access my BitBucket account (I use BitBucket for my Git repositories). The new machine already has Git installed. I simply used Chocolatey to install Git.

You can skip to full instructions in the BitBucket help if you like.

Step 1 – Check the .ssh directory

The first step is to check that you’ve got an folder called .ssh in your home directory. If it’s missing you need to create it.

SNAGHTML27c673c3

Step 2 – Create the default identity

Run ssh-keygen to create the key. If this is a fresh install there won’t be a default key so you can just hit enter to accept the default name or ender a new one if you want. Enter the passphrase when prompted.

SNAGHTML27c76c2d

Step 3 – Create an SSH config file

Create a config file for SSH.

SNAGHTML27c81a4f

Open the file and edit it. Add the following:

Host bitbucket.org
 IdentityFile ~/.ssh/id_rsa


Step 4 – Update the .bashrc file

Check you’ve got a .bashrc file in your home directory. Create one if you don’t. Open the .bashrc file and edit it. Add the following:

#! /bin/bash 
eval `ssh-agent -s` 
ssh-add ~/.ssh/*_rsa

See also Enter RSA passphrase once when using Git bash.

Close and reopen GitBash. You’ll be prompted for the passphrase.

SNAGHTML27c90088

Step 5 - Configure BitBucket to use the new key

Go to your BitBucket account and navigate to your settings. Adding the key is easy. Follow the steps here.

SNAGHTML27cc8153

SNAGHTML27ce99f2

Check you can access BitBucket using the new key.

SNAGHTML27cf57a4

Done.