48

My gitlab is on a virtual machine on a host server. I reach the VM with a non-standard SSH port (i.e. 766) which an iptable rule then forward from host:766 to vm:22.

So when I create a new repo, the instruction to add a remote provide a mal-formed URL (as it doesn't use the 766 port. For instance, the web interface give me this:

Malformed

git remote add origin git@git.domain.com:group/project.git

Instead of an URL containing :766/ before the group.

Wellformed

git remote add origin git@git.domain.com:766/group/project.git

So it time I create a repo, I have to do the modification manually, same for my collaborator. How can I fix that ?

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178

4 Answers4

104

In Omnibus-packaged versions you can modify that property in the /etc/gitlab/gitlab.rb file:

gitlab_rails['gitlab_shell_ssh_port'] = 766

Then, you'll need to reconfigure GitLab:

# gitlab-ctl reconfigure

Your URIs will then be correctly displayed as ssh://git@git.domain.com:766/group/project.git in the web interface.

mairas
  • 13
  • 5
Peque
  • 13,638
  • 11
  • 69
  • 105
  • 7
    You also need to make sure that ssh is told to listen on that port, otherwise the connection will be refused. By default it is /etc/ssh/sshd_config – HeroCC Aug 12 '16 at 01:45
  • 4
    I had to run `gitlab-ctl restart` in addition to `reconfigure` but after that, my ssh links on the web interface were updated. – Seth Mar 24 '17 at 13:23
  • 3
    When using the official gitlab docker container, the used sshd config file where the listen port also has to be changed is: /assets/sshd_config Restart sshd after editing the port using: /etc/init.d/ssh restart – sdl Aug 08 '17 at 15:11
  • If you also edit */etc/ssh/sshd_config*, don't forget to restart sshd, e.g. `service sshd restart`. – Kenny Evitt Oct 26 '18 at 14:37
  • Not working in my case, i have a gitlab in ec2 in private subnet behind an ELB, when i use 766, the git cant connect – user192344 Sep 15 '21 at 03:12
40

if you configure the ssh_port correctly in config/gitlab.yml, the webpages will show the correct repo url.

## GitLab Shell settings
gitlab_shell:
  ...
  # If you use non-standard ssh port you need to specify it
  ssh_port: 766

ps. the correct url is: ssh://git@git.domain.com:766/group/project.git

edit: after the change you need to clear caches, etc:

bundle exec rake cache:clear assets:clean assets:precompile RAILS_ENV=production
gdamjan
  • 998
  • 9
  • 12
  • That's what I'm doing and I got the correct URL in `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production'` output but not in the web interface – Édouard Lopez Aug 29 '13 at 17:36
  • seems there is a cache that was preventing the modification to appear in the web interface. Not sure what it is (sidekiq, gitlab) – Édouard Lopez Aug 30 '13 at 15:45
  • 1
    Assumming this is a bit old I have the same issue... you claim it was due o to a "cache" the modification from appearing? Could you clarify how to fix. Thanks. – luison Jun 25 '14 at 13:44
  • For omnibus installations this file can be found in: /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml – dersimn Dec 30 '14 at 22:47
  • @luison `bundle exec rake cache:clear assets:clean assets:precompile RAILS_ENV=production` – gdamjan Jan 23 '15 at 15:40
  • 1
    Just in case someone is having trouble with this and the env:info from @ÉdouardLopez is showing the correct urls, but the web interface not, you should restart apache, if you are using it. It worked for me. I guess unicorn is caching the data somehow. – func0der May 11 '15 at 07:39
  • 1
    Restarting the server fixed it for me (restarting nginx by itself didn't) if that helps anyone. – mike.bronner Apr 15 '16 at 21:47
5

N.B.: this was tested on an old Giltab version (v5-v6), and might not be suitable for modern instance.

You can achieve similar behavior in a 2 step process:

1. Edit: config/gitlab.yml

On the server, set the port to the one you use:

ssh_port: 766

2. Edit ~/.ssh/config

On your machine, add the following section corresponding to your gitlab:

Host sub.domain.com
        Port 766

Limit

You will need to repeat this operation on each user's computer…

References

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
0

Easy way to fix this issue:

ssh://git@my-server:4837/~/test.git
git clone -v ssh://git@my-server:4837/~/test.git

Reference URL

Willie Cheng
  • 7,679
  • 13
  • 55
  • 68