Bitbucket Pipeline - Pull/Push code using SSH Key without Permission denied
Asked by Luong Truong:

Hello guys, to be honest, I am struggling with the Bitbucket Pipeline

Below is my question with Bitbucket Pipeline

Scenario:

- I have 2 repos: Library and Package. Library contains the source code and the Package contains specific code that would be re-used in many projects.

- Bitbucket Pipeline is enable for both Library and Package repo.

- I write the code in Library repo, build, and push the final code to Package repo. Therefore, Library and Package repos need to communicate using Bitbucket Pipeline.

Question:

- How can I use SSH Key in Bitbucket Pipeline to pull/push code from Library repo to Package repo without the permission denied?

- According to this link: [the third comment from Maze Hawks](https://community.atlassian.com/t5/Bitbucket-questions/could-not-read-from-remote-repository/qaq-p/983015), adding the SSH Key to Personal Setting allow to do it, but do we have any alternative ways so we don't have to add the SSH Key to Personal Setting?

If you have any ideas, please feel free to give the answers or comments. I am really appreciated.


Answers:
author: Theodora Boudale
body: Hi [@Luong Truong](/t5/user/viewprofilepage/user-id/4226583) and welcome to the community!

```

- How can I use SSH Key in Bitbucket Pipeline to pull/push code from Library repo to Package repo without the permission denied?
```

If you want to use SSH, you can generate an SSH key pair from **Repository settings \> SSH keys** in the Library repo, then, copy the public key.

Afterwards, go to your **Personal settings \> SSH keys** and add the public key there.

If you have at least write access to Package repo, you'll be able to push this way from Pipelines of the Library repo.

```
- According to this link: the third comment from Maze Hawks, adding the SSH Key to Personal Setting allow to do it, but do we have any alternative ways so we don't have to add the SSH Key to Personal Setting?
```

Another way is to use ++HTTPS++. You can generate an app password for your account that has at least write access to repositories:

* <https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/>

Then to go Library **Repository settings \> Repository variables**

Create two variables, named e.g. **BitbucketUsername** and **BitbucketPassword** (please make sure that **BitbucketPassword** is created as a **secured** variable, so no one else can see it)

Afterwards, you can use an HTTPS URL like the following to push:

```
https://$BitbucketUsername:$BitbucketPassword@bitbucket.org/<workspace-id>/<repo-slug>.git
```

There is another option, which is to use ++OAuth++ for authentication. This is explained in detail here:

* <https://support.atlassian.com/bitbucket-cloud/docs/push-back-to-your-repository/#OAuth>

Please note that the example there assumes that you are pushing back to the same repo where Pipelines runs.

Since you want to push to a different repo, you can change the variable ${BITBUCKET_REPO_SLUG} in the URL with the repo slug of the repo you are pushing to.

Does any of these options work for you?

Please feel free to let me know if you have any questions.

Kind regards,  
Theodora

comments: author: Luong Truong
body: Hello [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) , thank you for your super clear answer. I am really appreciated.


Tags: bitbucket-cloud

bitbucket-pipelines