Use token to clone GitLab over SSH without SSH Key

Viewed 1072

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.

1 Answers

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.

Related