Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How can I use the Bitbucket API to add an SSH key to a Workspace?

I'm trying to work out how to add an SSH key to a Workspace.

There is this documentation for adding an SSH key to a User:

But I can't find anything for the Workspace, this call only adds an SSH key to my user.

When performing the action using the UI in a browser the users/%7Bselected_user%7D/ssh-keys call appears to happen, but I can't work out what is making it get added to the Workspace instead of the User.

Any help appreciated.

1 answer

0 votes
seanaty Atlassian Team Oct 15, 2021

What is your reason for adding an SSH to a workspace?

SSH keys are only meant to be added for users.

The closest thing to what I think you're looking for is called Access Keys. You can upload SSH keys for each individual repository to enable `git clone` and `git pull` (read only) access only. This is useful for running tests or for deploying.

At the moment this is repository by repository. However, hopefully we'll have a solution for group the same repository settings for a project (a collection of repositories).

Hi @seanaty,

We use git submodules, so are generating a Pipeline SSH Key for a repository, then adding the generated public key to the Workspace SSH keys, so Bitbucket Pipelines can access other repositories during a build.

Creating the Pipeline SSH Key is possible via this endpoint:<workspace>/<repo>/pipelines_config/ssh/key_pair/generate

When I create a Workspace SSH key via the UI it calls this endpoint:<user>/ssh-keys - but if I do that directly (e.g. with curl), the key is added to the User, not the Workspace and I can't work out why.
Any help, or update to the API docs, would be appreciated.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,229 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you