It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is there a way to upload an ssh key to stash via command line?

Yusuke Tsutsumi Oct 05, 2012

Hello,

I'm currently in the process of writing a script to get developers' environment set up. I would like to add ssh authentication to stash in the script, but I'm having some trouble. Is there a way I can add an ssh key to stash via the rest api or some way using curl or wget? I've tried using curl and emulating the request:

curl --user USERNAME:PASSWORD https://STASH_SERVER/plugins/servlet/ssh/keys/add --form "text=MY_SSH_KEY"

But no luck there. I don't have to programatically create a user, as the user already exists in stash at the time someone would run this script.

Thanks!

2 answers

1 accepted

3 votes
Answer accepted
Seb Ruiz Atlassian Team Oct 05, 2012

Yes, you can use our REST interfaces to add keys:

curl -u user:pass -X POST -H "Accept: application/json" -H "Content-Type: application/json" https://stash/rest/ssh/1.0/keys -d '{"text": "contents of public key file"}'

Yusuke Tsutsumi Oct 07, 2012

awesome, thanks!

Chhaya Gadade Sep 17, 2018

@Seb Ruiz:Thanks,it works fine for bitbucket Server.is there any way to add SSH key to Bitbucket Cloud.

Chhaya Gadade Sep 17, 2018

@Seb Ruiz:Thanks a lot for your quick reply,I have tried which you have provided but I am getting the error as:

<p>
CSRF verification failed. Request aborted.
</p>

<p>
Please enable 'Referer' headers for this site and try again.
</p>
Still not able to add SSH key to Bitbucket cloud instance.

Chhaya Gadade Sep 17, 2018

@Seb Ruiz:Hey thanks...it works...Authentication is required to add into curl command. 

1 vote
Michael Heemskerk Atlassian Team Oct 15, 2012

An addition to Seb's answer:

If you need to upload SSH keys for other users, you can add the ?user=<username> query parameter. If the 'user' query parameter is not provided, the REST resource defaults to the current user.

Note that you'll need at least Admin permissions to be able to upload SSH keys for other users.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

2,014 views 1 19
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