Gitlab with non-standard SSH port (on VM with Iptable forwarding)

你离开我真会死。 提交于 2019-12-09 04:08:30

问题


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 ?


回答1:


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



回答2:


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.




回答3:


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

  • GitLab and a non-standard SSH port


来源:https://stackoverflow.com/questions/18517189/gitlab-with-non-standard-ssh-port-on-vm-with-iptable-forwarding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!