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

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

2 votes
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"}'

1 vote

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

1,737 views 1 5
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