11

github provide public ssh key by URL like http://github.com/user.keys.

Is there a way also in bitbucket to obtain public keys via URL?

ironsand
  • 14,329
  • 17
  • 83
  • 176
  • 2
    I found this in a quick Google search: https://confluence.atlassian.com/display/BITBUCKET/ssh-keys+Resource – Cameron Tinker Apr 30 '14 at 19:54
  • Thanks, I can get by url `https://bitbucket.org/api/1.0/users/#{user}/ssh-keys`, but only if when I'm logged in. Is there no way without authentication? – ironsand Apr 30 '14 at 20:13
  • No, I'm afraid not. Public SSH keys are sensitive information and shouldn't be shared with any person who requests the API. – Cameron Tinker Apr 30 '14 at 20:14
  • 1
    You mean, github is doing wrong from security aspect? – ironsand Apr 30 '14 at 20:40
  • 4
    @CameronTinker, public keys are by definition *public*. Certainly PGP keys can be (and often are) shared publicly on key servers or on public websites. I would be very surprised if SSH public keys were sensitive from a security perspective. – ChrisGPT was on strike May 01 '14 at 12:06
  • 1
    @Chris Thanks for the clarification. Without the matching private key from the client, public key authentication won't work. It could just be that Bitbucket requires a login for their API and that's it. – Cameron Tinker May 01 '14 at 12:21
  • 2
    @CameronTinker, you got it! The private key is definitely sensitive, and should be carefully protected. I think your first comment in this thread is really the correct answer. Why not add it as one? – ChrisGPT was on strike May 01 '14 at 12:24

1 Answers1

5

Using Bitbucket's REST API version 1, you can get the SSH keys of a user with this endpoint:

https://bitbucket.org/api/1.0/users/#{user}/ssh-keys

Here is a full reference from the API documents:

https://confluence.atlassian.com/display/BITBUCKET/ssh-keys+Resource

I'm not sure if they plan to include this in version 2 of their API, but it should work with other API calls.

You need an account to authenticate your requests. Here is how to use the REST APIs: https://confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+REST+APIs

EDIT:
Here's the relevant documentation for v2 of their REST API:
https://developer.atlassian.com/bitbucket/api/2/reference/meta/authentication https://developer.atlassian.com/bitbucket/api/2/reference/resource/users/{username}/ssh-keys

Cameron Tinker
  • 9,634
  • 10
  • 46
  • 85