Cloning Bitbucket server repo with access tokens

Viewed 12184

I am trying to clone a bitbucket server repo (self-hosted) using access-token however I could not find any documentation on Bitbucket server API. My clone url is ssh based.

Or is there a way to use REST API curl command to clone bitbucket server repos?

2 Answers

The official documentation says that you should:

git clone https://x-token-auth:$ACCESS_TOKEN@yourbitbucketserver/...

In my experiments with a BitBucket 6.1 server, this does not work and gives HTTP 401 instead. Using ssh with access tokens seems to be entirely unsupported.

What did work was:

git -c "http.extraHeader=Authorization: Bearer $ACCESS_TOKEN" clone https://yourbitbucketserver/...

To clone over SSH you'll want to use an SSH key, note you can add more than one SSH key to a user account in Bitbucket Server, so you can identify with a specific SSH key if you'd like.

If you like the extra permission control that the Personal Access Tokens give you, you can clone over HTTPS, as our PATs are designed specifically for clone over HTTPS, and authenticating to the REST API using Basic Auth / Bearer token.

For more information see https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html

Related