- Step 1: Check for existing SSH keys
- Step 2: Generate a new SSH key
- Step 3: Copy your public key
- Step 4: Add your public key to Bitbucket
- Step 5: Test SSH connection to Bitbucket
- 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 | id_ed25519 |
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 | ~/.ssh/id_ed25519 |
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 | The authenticity of host 'bitbucket.org' can't be established. |
Type yes to continue. If everything is configured correctly, you will see:
1 | authenticated via ssh key. |
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 |