BitBucket SSH key generation tutorial

SSH key config with BitBucket steps

There are six relatively straightforward steps to configure SSH keys on BitBucket:

  1. Locally create a pair of private and public SSH keys with the ssh-keygen tool
  2. Copy the value of the public SSH key
  3. Log into BitBucket and navigate to your Personal Settings
  4. Click the SSH Keys link
  5. Add your BitBucket SSH Key to your Atlassian configuration
  6. Clone you BitBucket repo over SSH

Once you add the BitBucket SSH key to your personal settings, perform a git clone operation using the BitBucket SSH URL. To find this BitBucket SSH link, click the Clone button on the landing page of the repository you plan to work with.

SSH key generation

The following command to generate SSH keys runs in both Windows PowerShell and a Linux Terminal window:

PS C:\ssh\bitbucket\example> ssh-keygen -t rsa -o -C "[email protected]"

When asked for a passphrase and a location to store the BitBucket SSH keys, click return to accept the defaults.

The meaning of the ssh-keygen options are as follows:

  • The -o switch is needed to force the latest OpenSSH format.
  • The -t option allows you to choose the type of key to create. Here we choose an RSA key.
  • The -C option allows you to add a comment to the end of the public key.

You must store the BitBucket SSH keys in a directory named .ssh under the user’s home directory. If they are stored elsewhere, Git will not find them when it attempts to SSH to BitBucket. The files will be named and is_rsa

[email protected]~/.ssh$ ls is_rsa

BitBucket SSH config

Open the public key file named in a text editor, such as Emacs or Notepad++, and copy the value.

Public BitBucket SSH Key

Copy the public key so you can configure the SSH key in BitBucket.

Add a BitBucket SSH Key

With the public SSH key copied to your clipboard, log into BitBucket, navigate to Personal Preferences, click the SSH Keys link, and add the new BitBucket SSH key to your configuration.

BitBucket SSH Key

The BitBucket SSH key is configured in the Personal Preferences section of the admin console.

BitBucket SSH clone

Once the BitBucket SSH key is added to your personal preferences, click the Clone link on your BitBucket repository and copy the BitBucket SSH clone command. Enter this into PowerShell or a Terminal Window to clone your BitBucket repository with SSH.

A prompt will appear asking you to confirm the authenticity of the BitBucket SSH key. Type in yes and the BitBucket SSH clone will proceed.

git clone [email protected]:cameronmckenzie/learn-bitbucket-fast.git
Cloning SSH BitBucket repo into ‘learn-bitbucket-fast’…
Authenticity of BitBucket SSH Key Gen can't be established.
Do you want to proceed (type yes or no)? yes
Receiving objects over BitBucket SSH Key clone: 100% (777/777), done.
Resolving deltas from BitBucket over SSH: 100% (999/999), done.

After the process completes, use Git as you normally would. All future Git push, pull and fetch operation to BitBucket will happen over a secure shell.

And that’s how easy it is to configure SSH keys for BitBucket.