Install SSH key via command line?

I'd like to do something like 'ssh-copy-id' to place my SSH public key into bitbucket. I'm using ansible to set up a host, which has several steps that clone bitbucket repositories. Prior to that one needs to install the public SSH key into bitbucket. I'd like to automate this in ansible. Having a way to install the SSH key via the command line for bitbucket would allow this to be automated. Is this possible?

1 answer

0 votes
Pedro Cora Atlassian Team Jun 23, 2014

Hi Tom,

Browsing through the BitBucket API docs, this is not listed as a possible call. I'd say that this is not possible to achieve.

Check more details.


Thanks for the pointer! I can retrieve my ssh-keys by doing this:

curl -u tekberg> /tmp/c

In /tmp/c it has a list of dicts with keys "pk", "key" and "label". This way I can see if an ssh-key needs to be added or not.

When I try to add a new ssh-key:

curl -d - -X POST -u tekberg<<END

key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCgyRWiWhqoyanMeVWO0w522yK7lxVLKTR45u8LJ5R4HwRlVCqqx\




FdpZBz tekberg@apps3"

label: ""


(Note: the key: is all in one line. The label is on the next line.)

I get the following HTML:

<ul class="errorlist"><li>key<ul class="errorlist"><li>This field is required.</li></ul></li></ul>

I think it is saying that the key field is required. Obviously I'm not specifying that field properly. I tried another variation with the keys quoted - "key" and "label" - with the same result.

I think I'm pretty close. Can you tell me how to properly specify the 'key' field?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 14, 2019 in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

256 views 0 12
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you