Site Overlay

Setting up VS Code with GitLab with custom SSH port

As explained in my previous blog, it is often necessary to run the SSH server inside a GitLab Docker stack on a non-standard port as the default port 22 is reserved for ssh’ing into the server itself. One way to work around that problem is to forward a a non standard port like 1022 on the host machine into the GitLab container’s port 22.

Now how do we handle with such port forwardings on the IDE side?

Cloning a repo from your GitLab server

After you set up a new project on your GitLab server, the project home page shows a Clone button:

GitLab Project homepage with Clone button

Now you have got several options: Among those are generic SSH and http links which you can copy and paste to your command line, plus there are links for cloning the Repo into VS Code directly and which do not work for my machine.

If you connect through a non-standard ssh port, you cannot directly paste the string from the Clone button template into the version control dialogue of your preferred programming IDE. GitLab explains how to amend repo URLs for custom ports in a merge request.

VS Code side

In VS Code, click on the Source Control Icon at the left side of the screen and then click on Clone Repository as shown in the following image:

Opening the dialogue for cloning repositories from VS Code’s source control section.

Then copy the URL string from the Clone with SSH section of your GitLab project. In my case, this is assumed to be

Before pasting this string into the dialogue of your VS Code, you have to made amendment’s for the non-default SSH port as per the instructions given by GitLab. In my case, the amending the link according to the first template provided worked out of the box with GitLab:

This is just the URL which you have to paste into the text box which opens upon pressing Clone Repository in VS Code. You will then be asked for a local folder to sync the repo into from the GitLab server.

The generic composition of the SSH repo URL for VS code is: