{"id":1801,"date":"2023-04-03T21:28:51","date_gmt":"2023-04-03T19:28:51","guid":{"rendered":"https:\/\/hobbykeller.spdns.de\/?p=1801"},"modified":"2023-04-08T22:55:10","modified_gmt":"2023-04-08T20:55:10","slug":"setting-up-vs-code-with-gitlab-with-custom-ssh-port","status":"publish","type":"post","link":"https:\/\/hobbykeller.spdns.de\/?p=1801","title":{"rendered":"Setting up VS Code with GitLab with custom SSH port"},"content":{"rendered":"\n<p>As explained in my <a href=\"https:\/\/hobbykeller.spdns.de\/?p=1789\" data-type=\"post\" data-id=\"1789\">previous blog<\/a>, 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&#8217;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&#8217;s port 22.<\/p>\n\n\n\n<p>Now how do we handle with such port forwardings on the IDE side?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cloning a repo from your GitLab server<\/h2>\n\n\n\n<p>After you set up a new project on your GitLab server, the project home page shows a Clone button:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-14-13-38.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"518\" src=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-14-13-38-1024x518.png\" alt=\"\" class=\"wp-image-1806\" srcset=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-14-13-38-1024x518.png 1024w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-14-13-38-300x152.png 300w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-14-13-38-768x389.png 768w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-14-13-38-180x90.png 180w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-14-13-38.png 1091w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">GitLab Project homepage with Clone button<\/figcaption><\/figure>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-simple-alerts-for-gutenberg-alert-boxes sab-alert sab-alert-primary\" role=\"alert\">Keep in mind that GitLab always assumes that it uses the default port 22 for pushing and pulling over SSH. If you have remapped the GitLab&#8217;s SSH port to an alternative number, you have to adapt the links provided by the GitLab clone button.<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">\u00d7<\/span><\/button><\/div>\n\n\n\n<p>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 <a rel=\"noreferrer noopener\" href=\"https:\/\/gitlab.com\/gitlab-org\/gitlab-vscode-extension\/-\/merge_requests\/736\" target=\"_blank\">how to amend repo URLs for custom ports<\/a> in a merge request.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">VS Code side<\/h2>\n\n\n\n<div class=\"wp-block-simple-alerts-for-gutenberg-alert-boxes sab-alert sab-alert-info\" role=\"alert\">Although there are VS Code add-ons available for GitLab, it is not necessary to install any such an add in as the default installation of VS Code is perfectly equipped to interact with GitLab repos.<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">\u00d7<\/span><\/button><\/div>\n\n\n\n<p>In VS Code, click on the <strong>Source Control<\/strong> Icon at the left side of the screen and then click on <strong>Clone Repository<\/strong> as shown in the following image:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-20-17-18.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"380\" src=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-20-17-18-1024x380.png\" alt=\"\" class=\"wp-image-1808\" srcset=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-20-17-18-1024x380.png 1024w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-20-17-18-300x111.png 300w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-20-17-18-768x285.png 768w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2023\/04\/Screenshot-from-2023-04-03-20-17-18.png 1027w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Opening the dialogue for cloning repositories from VS Code&#8217;s source control section.<\/figcaption><\/figure>\n\n\n\n<p>Then copy the URL string from the Clone with SSH section of your GitLab project. In my case, this is assumed to be<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \" title=\"Unamended GitLab project URL for cloning with standard SSH port\">git@q556.fritz.box:ilek\/pybbg.git<\/pre><\/div>\n\n\n\n<p>Before pasting this string into the dialogue of your VS Code, you have to made amendment&#8217;s for the non-default SSH port as per the <a rel=\"noreferrer noopener\" href=\"https:\/\/gitlab.com\/gitlab-org\/gitlab-vscode-extension\/-\/merge_requests\/736\" target=\"_blank\">instructions given by GitLab<\/a>. In my case, the amending the link according to the first template provided worked out of the box with GitLab:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \" title=\"GitLab URL with non-standard portnumber for use with VS Code\">[git@q556.fritz.box:1022]:ilek\/pybbg.git<\/pre><\/div>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>The generic composition of the SSH repo URL for VS code is:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:default decode:true \" title=\"Generic GitLab URL with non-standard SSH port for VS Code\">[git@SERVERURL:PORTNUMBER]:USER\/REPOSLUG.git<\/pre><\/div>\n\n\n\n<div class=\"wp-block-simple-alerts-for-gutenberg-alert-boxes sab-alert sab-alert-primary\" role=\"alert\"><strong>Hint:<\/strong><br>You can also use the above SSH template to clone a git repository directly from the console. Use <code>git clone [git@q556.fritz.box:1022]:ilek\/pybbg.git<\/code>.<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">\u00d7<\/span><\/button><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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<span class=\"more-button\"><a href=\"https:\/\/hobbykeller.spdns.de\/?p=1801\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\">Setting up VS Code with GitLab with custom SSH port<\/span><\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[369,371,370],"class_list":["post-1801","post","type-post","status-publish","format-standard","hentry","category-linux","tag-gitlab","tag-ssh-port","tag-vs-code"],"_links":{"self":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1801"}],"version-history":[{"count":5,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1801\/revisions"}],"predecessor-version":[{"id":1819,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1801\/revisions\/1819"}],"wp:attachment":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}