Terraform IaC Tool | Multibranch Pipeline with Git

Access Another Bitbucket Repository From a Bitbucket Pipelines

Fix the “ERR! Unauthorized, fatal: Could not read from remote repository” error

Andrea Perera
3 min readJul 27, 2024
Snapshot of the Error message

You may have encountered this error before. It commonly occurs when attempting to clone a Bitbucket repository from another Bitbucket repository pipeline. Here are a few steps you can follow to resolve this error.

Let’s say you want to clone the mycomponents repository from themyapp repository pipeline. Themyapp repository that triggers the pipeline will need permission to clonemycomponents.

Create a repository

Clone over SSH

git clone git@bitbucket.org:<workspace-or-project-name>/<repository-name>.git

Clone over HTTPS

git clone https://<username>@bitbucket.org/<workspace-or-project-name>/<repository-name>.git

example: git clone git@bitbucket.org:my-project/mycomponents.git

1. Create an SSH key

First, you need to create an SSH key in the myapp repository.

  • In Bitbucket, go to the repository SSH keys page. Repository Settings > Pipelines > SSH keys.
  • Click on theGenerate keys button below to auto-generate a random, secure SSH key pair. You can also upload a custom key pair if you prefer.
The repository SSH keys page

Once Bitbucket auto-generates a random secure SSH key pair, as you see below, click on theCopy public key button to copy the public key.

Auto-generate a random, secure SSH key pair

2. Add SSH public key

Now you need to add the created SSH key to the mycomponent repository

  • Go to the mycomponentrepository, select Repository Settings, andGeneral > Access keys. click on theAdd key button to add the public key.
Add access key page in Bitbucket
  • You will get a popup to add the SSH key, give a label name for the key, and paste the previously copied public key into the key section.
Snapshot of “Add SSH key” popup

Ta-da 🥳, now yourmyapp repository has read-only permissions to clone the mycomponents repository.

"ERR! Unauthorized, fatal: Could not read from remote repository " error is no more.

References :

https://support.atlassian.com/bitbucket-cloud/docs/using-ssh-keys-in-bitbucket-pipelines/

--

--

Andrea Perera

Technical Writer | Software Engineer | MSc in Big Data Analytics | Email:andriperera.98@gmail.com | Linkedin: Andrea Perera