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.
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.
Step 3 – Create an SSH config file
Create a config file for SSH.
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.
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.
Check you can access BitBucket using the new key.
Done.