1

I need to clone a GitLab (custom instance) repository from a script using an authentication (or deploy) token.

I've seen and tried Using GitLab token to clone without authentication (and others) for how to do that with an https URL scheme, but this GitLab instance has http access disabled.

How to use the authentication token with an ssh URL? I can't seem to find any example, even in the official documentation.

Cilyan
  • 7,883
  • 1
  • 29
  • 37

1 Answers1

3

you can not use a token to clone via ssh, what you need is an SSH-key.

There are a few ways you can achieve this:

  1. either use your own key (not recommended)
  2. create a Deploy key (Settings -> Repository -> Deploy Key)

To use a custom key within a script you can take a look at How to specify the private SSH-key to use when executing shell command on Git? - which explains different ways of setting a custom ssh key for the checkout.

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36
  • Thanks. That's what I also thought, but here and there in the documentation they seem to imply that it is possible without saying how, like if it was obvious. I'm going to try your solution. (Of course, option 1 is for me a no go, and the reason why I want to use tokens, or at least a key that gives only read-only rights). – Cilyan Oct 19 '21 at 12:55