Skip to content

Instantly share code, notes, and snippets.

@cbmeeks
Created March 14, 2025 20:23
Show Gist options
  • Save cbmeeks/643a292a3599046056c4cced77204410 to your computer and use it in GitHub Desktop.
Save cbmeeks/643a292a3599046056c4cced77204410 to your computer and use it in GitHub Desktop.
Connect to Bitbucket with SSH

Step 1: Check if SSH is Installed

  1. Open a terminal.

  2. Run: ssh -v

    • If it shows a version (e.g., OpenSSH), SSH is installed. If not, install it with:
      sudo apt update
      sudo apt install openssh-client

Step 2: Generate an SSH Key

  1. In the terminal, generate a new SSH key:
    ssh-keygen -t ed25519 -C "[email protected]"
  2. Press Enter to accept the default file location (~/.ssh/id_ed25519 or ~/.ssh/id_rsa).
  3. Optionally, enter a passphrase for extra security (or leave blank).

Step 3: Start the SSH Agent

  1. Start the SSH agent:
    eval "$(ssh-agent -s)"
  2. Add your SSH private key to the agent:
    ssh-add ~/.ssh/id_ed25519
    • Use ~/.ssh/id_rsa if you generated an RSA key instead.

Step 4: Copy Your Public Key

  1. Display your public key:
    cat ~/.ssh/id_ed25519.pub
    • Or cat ~/.ssh/id_rsa.pub for RSA.
  2. Copy the output (starts with ssh-ed25519 or ssh-rsa).

Step 5: Add the SSH Key to Bitbucket

  1. Log in to your Bitbucket account.
  2. Go to Personal settings > SSH keys.
  3. Click Add key.
  4. Paste your public key (from Step 4) and give it a label (e.g., "Ubuntu PC").
  5. Save it.

Step 6: Test the Connection

  1. In the terminal, test the connection to Bitbucket:
  2. If successful, you’ll see a message like:
    "authenticated via ssh key ... You can use git to connect to Bitbucket..."

Step 7: Clone or Use a Repository

  1. On Bitbucket, go to your repository and copy the SSH URL (e.g., [email protected]:username/repo.git).
  2. In the terminal, clone it:
    git clone [email protected]:username/repo.git
    • Replace the URL with your repository’s SSH URL.

Troubleshooting

  • If you get a "Permission denied" error:
    • Ensure your public key is correctly added to Bitbucket.
    • Check file permissions: chmod 600 ~/.ssh/id_ed25519 (or id_rsa).
  • If asked about the host key, type yes to accept it.

That’s it! You should now be connected to Bitbucket via SSH on Ubuntu. Let me know if you run into any issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment