Accessing Bitbucket Git repositories over SSH

  1. Step 1: Check for existing SSH keys
  2. Step 2: Generate a new SSH key
  3. Step 3: Copy your public key
  4. Step 4: Add your public key to Bitbucket
  5. Step 5: Test SSH connection to Bitbucket
  6. Step 6: Use SSH to connect to your repository

Accessing Bitbucket Git repositories over SSH is a secure way to perform Git operations without using a username and password.

Here’s a step-by-step guide:

Step 1: Check for existing SSH keys

1
ls -al ~/.ssh

If you see files like:

1
2
id_ed25519
id_ed25519.pub

You already have a key and can skip to Step 3.

Step 2: Generate a new SSH key

The ED25519 algorithm is highly recommended for generating a key:

1
ssh-keygen -t ed25519 -C "[email protected]"

You will be prompted to enter a file to save the key, like:

1
Enter file in which to save the key (/home/username/.ssh/id_ed25519):

Press Enter to continue. Then:

1
Enter passphrase (empty for no passphrase):

Enter a passphrase. Using a strong passphrase is a security best practice, although you can leave it empty for automated systems.

This command creates two files:

1
2
~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub

Step 3: Copy your public key

Run:

1
cat ~/.ssh/id_ed25519.pub

You will see something like:

1
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...... [email protected]

Copy the whole line. Note: Please copy the content of id_ed25519.pub instead of id_ed25519. The latter is your private key, don’t share it with anyone!

Step 4: Add your public key to Bitbucket

Visit https://bitbucket.org/account/settings/ssh-keys/ and click the Add key button, then paste your public key into the text box, give it a descriptive label, and click Add key.

Step 5: Test SSH connection to Bitbucket

In your terminal, run ssh -T [email protected].

You might see something like:

1
2
The authenticity of host 'bitbucket.org' can't be established.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Type yes to continue. If everything is configured correctly, you will see:

1
2
3
authenticated via ssh key.

You are authenticated as yourusername.

Step 6: Use SSH to connect to your repository

In Bitbucket, navigate to your repository and click the Clone button.

Ensure the SSH protocol is selected. The URL will look like [email protected]:workspace/repository.git or ssh://[email protected]/workspace/repository.git.
Use this URL with Git commands:

1
git clone [email protected]:workspace/repository.git