# Make CI Runner clone using SSH, not HTTPS

**URL:** <https://forum.gitlab.com/t/make-ci-runner-clone-using-ssh-not-https/5291>\
**Category:** GitLab CI/CD\
**Created:** [December 2, 2016, 5:23pm UTC](https://forum.gitlab.com/t/make-ci-runner-clone-using-ssh-not-https/5291 "2016-12-02T17:23:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjcmarx](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mjcmarx](https://forum.gitlab.com/u/mjcmarx)\
**Post date:** [December 2, 2016, 5:23pm UTC](https://forum.gitlab.com/t/make-ci-runner-clone-using-ssh-not-https/5291/1 "2016-12-02T17:23:23Z")

</div>

Hi,

Does anyone know if there is a way to ensure the runner uses SSH for cloning as opposed to HTTPS while the GitLab server is setup for HTTPS? Since I have changed over to HTTPS on the GitLab server it seems the runner automatically tries HTTPS (probably due to the CI URL?).

I have also disabled the proxy, but the result remains the same.

Cloning repository…  
Cloning into ‘/home/gitlab-runner/builds/34200655/0/name/project’…  
fatal: unable to access ‘[https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab-server/name/project.git/](https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab-server/name/project.git/)’: Received HTTP code 503 from proxy after CONNECT  
ERROR: Build failed: exit status 1

Thank you very much for the assistance!

---

<div class="post-metadata">

**Author:** ![mjcmarx](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mjcmarx](https://forum.gitlab.com/u/mjcmarx)\
**Post date:** [December 7, 2016, 11:58am UTC](https://forum.gitlab.com/t/make-ci-runner-clone-using-ssh-not-https/5291/2 "2016-12-07T11:58:56Z")

</div>

The error has been resolved (my bad)

But my question still remains… can the runner use the SSH URL as opposed to the HTTPS URL?

---

<div class="post-metadata">

**Author:** ![mntbighker](https://sea2.discourse-cdn.com/gitlab/user_avatar/forum.gitlab.com/mntbighker/32/2589_2.png) [@mntbighker](https://forum.gitlab.com/u/mntbighker)\
**Post date:** [December 13, 2018, 8:52pm UTC](https://forum.gitlab.com/t/make-ci-runner-clone-using-ssh-not-https/5291/3 "2018-12-13T20:52:46Z")

</div>

Same question here, since we don’t use http git. Are we barking up the wrong tree trying to do everything over port 22? There is so much conflicting and incomplete information in the gitlab docs that I don’t know which end is up. We use no virtualization at all. We just want a runner on the compute cluster talking to the gitlab server on port 22. So far all attempts have failed, and the error I see is about an unsupported key. I get the feeling that really only virtual container runners are really supported.

---

<div class="post-metadata">

**Author:** ![mfriedenhagen](https://sea2.discourse-cdn.com/gitlab/user_avatar/forum.gitlab.com/mfriedenhagen/32/9733_2.png) [@mfriedenhagen](https://forum.gitlab.com/u/mfriedenhagen)\
**Post date:** [December 23, 2018, 8:51am UTC](https://forum.gitlab.com/t/make-ci-runner-clone-using-ssh-not-https/5291/4 "2018-12-23T08:51:41Z")

</div>

I do not understand your usecase:

- the runner connects to the GitLab-server via https, so cloning via https should always be possible and is done automatically by the runner itself (at least if you use docker)
- if you want to do additional clones for n your script, you need to add a valid ssh-key but just using the **CI\_JOB\_TOKEN** with https is much easier.

---

<div class="post-metadata">

**Author:** ![kayman-mk](https://avatars.discourse-cdn.com/v4/letter/k/aeb1de/32.png) [@kayman-mk](https://forum.gitlab.com/u/kayman-mk)\
**Post date:** [July 12, 2022, 9:59pm UTC](https://forum.gitlab.com/t/make-ci-runner-clone-using-ssh-not-https/5291/5 "2022-07-12T21:59:28Z")

</div>

A very old thread, but the problems are still present.

I tried several solutions but all have drawbacks: not efficient, dirty repository, … I started to [add this functionality to the Gitlab Runner](https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/3518). But I guess there will be no backport to older versions. Unfortunately I have to use Runner 14.8. So I started a fresh clone at [Hapag-Lloyd/Gitlab-Runner](https://gitlab.com/hapag-lloyd/gitlab-runner).

Feel free to add a MR to enable SSH cloning for other versions as well. Just a few lines of code to enable it and a little bit of configuration in the `config.toml`:

```auto
[runners]
clone_url="ssh://git@my.instance.cloud"

```

---

<div class="post-metadata">

**Author:** ![scruel](https://sea2.discourse-cdn.com/gitlab/user_avatar/forum.gitlab.com/scruel/32/39172_2.png) [@scruel](https://forum.gitlab.com/u/scruel)\
**Post date:** [June 20, 2024, 6:56am UTC](https://forum.gitlab.com/t/make-ci-runner-clone-using-ssh-not-https/5291/6 "2024-06-20T06:56:09Z")

</div>

```auto
Using Docker executor with image python:3.10 ...
Getting source from Git repository  
Fetching changes with git depth set to 20
Reinitialized existing Git repository in /builds/scruel/test-ssh/.git/
error: cannot run ssh: No such file or directory
fatal: unable to fork

```

---

<div class="post-metadata">

**Author:** ![tom137](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@tom137](https://forum.gitlab.com/u/tom137)\
**Post date:** [June 19, 2025, 5:48am UTC](https://forum.gitlab.com/t/make-ci-runner-clone-using-ssh-not-https/5291/7 "2025-06-19T05:48:36Z")

</div>

I thought I’d post my unoptimal solution for this after failing to find any answer.

Start with disabling the auto git clone

```auto
variables:
  GIT_STRATEGY: none

```

then in the `before_script` I collect the a base64 encoded masked private key I’ve stored as a CI variable, set a custom `GIT_SSH_COMMAND`, then navigate to the empty `CI_PROJECT_DIR` created automatically and checkout the the runner `CI_COMMIT_SHA`

```auto
    - echo "$SSH_PRIVATE_KEY" | base64 -d > /tmp/ci_key
    - chmod 600 /tmp/ci_key

    - export GIT_SSH_COMMAND="ssh -i /tmp/ci_key -F /dev/null"

    - |
      cd "$CI_PROJECT_DIR"
      git init
      git remote add origin ssh://git@...
      git fetch --depth 20 origin "$CI_COMMIT_SHA"
      git checkout -q "$CI_COMMIT_SHA"

```

I’m not a huge fan of this approach but it seems to work.
