Set up Project Access keys on Linux

Add access keys to your Bitbucket Cloud projects to allow a user or service to authenticate when pulling or cloning any repository over SSH that is included in your project. 

An access key has the following features and limitations:

  • Grant read-only access to a public or private project.

  • Don't require additional users on your plan.

  • Can be added to multiple projects.

  • Can't also be associated with an account.

  • Don't require a passphrase when used for automated processes.

Before you can add an access key to a project, you'll need to generate a unique SSH key just as you would for your individual account. To generate and add an SSH key:

  1. Install OpenSSH on your device.

  2. Start the SSH Agent.

  3. Create an SSH key pair.

  4. Add your key to the SSH agent.

  5. Provide Bitbucket Cloud with your public key.

  6. Check that your SSH authentication works.

Install OpenSSH on Linux

To install OpenSSH, we recommend using the OpenSSH package provided by your Linux distribution.

  • For Debian, Ubuntu, Linux Mint, and other Debian-based distributions:

    1 sudo apt update && sudo apt install openssh-client
  • For Fedora, CentOS, Red Hat Enterprise Linux, Oracle Linux, and other Fedora-based distributions:

    1 sudo dnf install openssh-clients
  • For Arch Linux and other Arch Linux-based distributions:

    1 sudo pacman -Sy openssh
  • For SUSE Linux, openSUSE Linux, and other SUSE-based distributions:

    1 sudo zypper install openssh

In the terminal, check that OpenSSH has been successfully installed by running the following command:

1 ssh -V

The output should show the installed version of OpenSSH.

Start the SSH agent

To allow git to use your SSH key, an SSH agent needs to be running on your device.

To check if it is already running, run the ps command. If the ssh-agent is already running, it should appear in the output, such as:

1 2 $ ps -auxc | grep ssh-agent myusername 3291 0.0 0.0 6028 464 ? Ss 07:29 0:00 ssh-agent

To start the agent, run:

1 eval $(ssh-agent)

You may need to add this command to your ~/.bashrc, ~/.zshrc, ~/.profile, or equivalent shell configuration file. Adding this command to a shell configuration file will ensure the agent is running when you open a terminal.

Create an SSH key pair

To create an SSH key pair:

  1. Open a terminal and navigate to your home or user directory using cd, for example:

    1 cd ~
  2. Generate a SSH key pair using ssh-keygen, such as:

    1 ssh-keygen -t ed25519 -b 4096 -C "{username@emaildomain.com}" -f {ssh-key-name}

    Where:

    • {username@emaildomain.com} is the email address associated with the Bitbucket Cloud account, such as your work email account.

    • {ssh-key-name} is the output filename for the keys. We recommend using a identifiable name such as bitbucket_work.

  3. When prompted to Enter passphrase, you can either provide a password or leave the password empty. If you input a password, you will be prompted for this password each time SSH is used, such as using Git command that contact Bitbucket Cloud (such as git push, git pull, and git fetch). Providing a password will prevent other users with access to the device from using your keys.

Once complete, ssh-keygen will output two files:

  • {ssh-key-name} — the private key.

  • {ssh-key-name}.pub — the public key.

Add your key to the SSH agent

To add the SSH key to your SSH agent (ssh-agent):

  1. Run the following command, replacing the {ssh-key-name} with the name of the private key:

    1 ssh-add ~/{ssh-key-name}
  2. To ensure the correct SSH key is used when connecting to Bitbucket, update or create your SSH configuration file (~/.ssh/config) with the following settings:

    1 2 3 Host bitbucket.org AddKeysToAgent yes IdentityFile ~/.ssh/{ssh-key-name}

    Where {ssh-key-name} is the location of the private key file once it has been added to the ssh-agent.

Provide Bitbucket Cloud with your public key

To add an SSH key to a Bitbucket Project:

  1. At bitbucket.org, select Projects on the navigation bar at the top of the screen.

  2. Select the project from the list.

  3. Select Project settings.

  4. Under General, select Access keys.

  5. Select Add key.

  6. In the Add SSH key dialog, provide a Label to help you identify which key you are adding. For example, Work Laptop <Manufacturer> <Model>. A meaning full label will help you identify old or unwanted keys in the future.

  7. Open the public SSH key file (public keys have the .pub file extension) in a text editor. The public key should be in the .ssh/ directory of your user (or home) directory. The contents will be similar to:

    1 ssh-ed25529 LLoWYaPswHzVqQ7L7B07LzIJbntgmHqrE40t17nGXL71QX9IoFGKYoF5pJKUMvR+DZotTm user@example.com
  8. Copy the contents of the public key file and paste the key into the Key field of the Add SSH key dialog.

  9. Select Add SSH key.

    • If the key is added successfully, the dialog will close and the key will be listed on the Access keys page.

    • If you receive the error That SSH key is invalid, check that you copied the entire contents of the public key (.pub file).

Check that your SSH authentication works

To test that the SSH key was added successfully, open a terminal on your device and run the following command:

1 ssh -T git@bitbucket.org

If SSH can successfully connect with Bitbucket using your SSH keys, the command will produce output similar to:

1 2 3 authenticated via ssh key. You can use git to connect to Bitbucket. Shell access is disabled

 

Additional Help