Set up Project Access keys on macOS

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 macOS

A version of OpenSSH should be pre-installed on macOS. To check if OpenSSH is installed, open a terminal and run:

1 ssh -V

The output should show the installed version of OpenSSH.

To use Homebrew to install a newer version of OpenSSH, run:

1 brew install openssh

To check that OpenSSH was installed successfully, run:

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 -ax | grep ssh-agent 19998 ?? 0:00.20 /usr/bin/ssh-agent -l

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

 

 

Still need help?

The Atlassian Community is here for you.