# Cloning another private repo in the build

**URL:** <https://discuss.circleci.com/t/cloning-another-private-repo-in-the-build/25505>\
**Category:** Build Environment\
**Created:** [September 30, 2018, 4:20pm UTC](https://discuss.circleci.com/t/cloning-another-private-repo-in-the-build/25505 "2018-09-30T16:20:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![grzegorzu](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/grzegorzu/32/19297_2.png) [@grzegorzu](https://discuss.circleci.com/u/grzegorzu)\
**Post date:** [September 30, 2018, 4:20pm UTC](https://discuss.circleci.com/t/cloning-another-private-repo-in-the-build/25505/1 "2018-09-30T16:20:49Z")

</div>

Hi guys, I have a question regarding cloning another private repository. Let’s say I have two repositories: my-app-backend and my-app-frontend. When going through the workflow with my-app-backend, during one step, I want to clone the frontend repository to run some tests. I’ve set up SSH keys already, namely:

- I generated new public and private SSH keys.
- The repository is on Github so I visited the frontend repo, Settings -\> Deploy keys and according to hints I added the public SSH key which was required.

- On CircleCI’s end, in the backend app, I visited Settings -\> SSH Permissions and I added the private key which was required.
- Both fingerprints (on Github and CircleCI) are the same.

The problem occurs while cloning the frontend repository. I’m getting the following error:

```
Cloning into '/home/circleci/my-app-frontend'...
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Exited with code 128

```

I’m pretty sure that with CircleCI 1.0 it would work, but with 2.0 I have no idea. Am I doing anything wrong or should I consider adding a machine user which, in my opinion, would be an overkill since I need to do it only in one repository, not everywhere?

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [September 30, 2018, 5:57pm UTC](https://discuss.circleci.com/t/cloning-another-private-repo-in-the-build/25505/2 "2018-09-30T17:57:38Z")

</div>

It should work just fine. Can we see your `config.yml`? Did you use [`add_ssh_keys`](https://circleci.com/docs/2.0/configuration-reference/#add_ssh_keys) prior to the `git clone`?

> [@grzegorzu](#):
>
> should I consider adding a machine user

No, you have a default (root) user in your container, and you don’t need another one.

---

<div class="post-metadata">

**Author:** ![grzegorzu](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/grzegorzu/32/19297_2.png) [@grzegorzu](https://discuss.circleci.com/u/grzegorzu)\
**Post date:** [September 30, 2018, 7:18pm UTC](https://discuss.circleci.com/t/cloning-another-private-repo-in-the-build/25505/3 "2018-09-30T19:18:38Z")

</div>

I totally forgot to include the config file, sorry about that! Here’s the snippet of the file:

```
version: 2

defaults: &defaults
  working_directory: ~/my-app-backend
  docker:
    - image: circleci/ruby:2.5.1-stretch-browsers
      environment:
        BUNDLE_JOBS: 4
        BUNDLE_RETRY: 3
        BUNDLE_PATH: vendor/bundle
        RAILS_ENV: test
    - image: circleci/postgres:9.6.8-alpine-ram
      environment:
        POSTGRES_USER: my-app-backend
        POSTGRES_DB: my-app-backend_test
        POSTGRES_PASSWORD: ""
run_feature_tests:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: ~/my-app-backend
      - add_ssh_keys:
          fingerprints:
            - "<here's the finger print>"
      - run:
          name: Clone frontend repository
          command: >-
            GIT_SSH_COMMAND='ssh -i ~/.ssh/id_rsa_fingerprint'
            git clone git@github.com:user/my-app-frontend.git ~/my-app-frontend
```

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [September 30, 2018, 8:48pm UTC](https://discuss.circleci.com/t/cloning-another-private-repo-in-the-build/25505/4 "2018-09-30T20:48:54Z")

</div>

A couple of things to try:

- Put `-v` or `-vv` etc in your `ssh` line to see if you can get some logs
- Make sure you’re actually using an RSA format pair (some encryption algos are not supported)
- Try adding a continuation `\` char at the end of your `GIT_SSH_COMMAND` line, so the whole thing is one line (I don’t think it would otherwise need `export`, but it is worth a try).

---

<div class="post-metadata">

**Author:** ![grzegorzu](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/grzegorzu/32/19297_2.png) [@grzegorzu](https://discuss.circleci.com/u/grzegorzu)\
**Post date:** [October 1, 2018, 11:53am UTC](https://discuss.circleci.com/t/cloning-another-private-repo-in-the-build/25505/5 "2018-10-01T11:53:02Z")

</div>

I added `-v` option in the `ssh` command and here’s the output:

```
#!/bin/bash -eo pipefail
GIT_SSH_COMMAND='ssh -v -i ~/.ssh/id_rsa_<fingerprint>' git clone git@github.com:user/my-app-frontend.git ~/my-app-frontend
Cloning into '/home/circleci/my-app-frontend'...
OpenSSH_7.4p1 Debian-10+deb9u4, OpenSSL 1.0.2l 25 May 2017

debug1: Reading configuration data /home/circleci/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/circleci/.ssh/id_rsa_<fingerprint> type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/circleci/.ssh/id_rsa_<fingerprint>-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u4
debug1: Remote protocol version 2.0, remote software version libssh_0.7.0
debug1: no match: libssh_0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:<key>
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/circleci/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: 
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.253.112]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = C.UTF-8
debug1: Sending command: git-upload-pack 'user/my-app-frontend.git'
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
ERROR: Repository not found.
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK

Transferred: sent 2756, received 1704 bytes, in 0.0 seconds

Bytes per second: sent 64184.2, received 39684.3

debug1: Exit status 1

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Exited with code 128

```

When it comes to `\` at the end of `GIT_SSH_COMMAND` line it didn’t work, cause I got:

```
#!/bin/bash -eo pipefail
GIT_SSH_COMMAND='ssh -v -i ~/.ssh/id_rsa_<fingerprint>'\ git clone git@github.com:user/my-app-frontend.git ~/my-app-frontend
/bin/bash: clone: command not found
Exited with code 127

```

Exporting `GIT_SSH_COMMAND` described like [here](https://circleci.com/docs/2.0/env-vars/#using-bash_env-to-set-environment-variables) didn’t work either.

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [October 1, 2018, 2:13pm UTC](https://discuss.circleci.com/t/cloning-another-private-repo-in-the-build/25505/6 "2018-10-01T14:13:01Z")

</div>

You need to configure CircleCI to be able to checkout additional private projects. It’s a security/SSH issue: [https://circleci.com/docs/2.0/gh-bb-integration/#enable-your-project-to-check-out-additional-private-repositories](https://circleci.com/docs/2.0/gh-bb-integration/#enable-your-project-to-check-out-additional-private-repositories)

I think maybe you added a regular SSH key that CircleCI would use for deployments vs a checkout key it needs for GitHub.

---

<div class="post-metadata">

**Author:** ![grzegorzu](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/grzegorzu/32/19297_2.png) [@grzegorzu](https://discuss.circleci.com/u/grzegorzu)\
**Post date:** [October 1, 2018, 3:06pm UTC](https://discuss.circleci.com/t/cloning-another-private-repo-in-the-build/25505/7 "2018-10-01T15:06:54Z")

</div>

You’re right, adding additional checkout SSH key solved the problem. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [October 11, 2018, 3:06pm UTC](https://discuss.circleci.com/t/cloning-another-private-repo-in-the-build/25505/8 "2018-10-11T15:06:55Z")

</div>

Closed on October 11, 2018, 3:06pm UTC

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
