Change SSH host for cloning - gitlab

Is there any way to change default ssh host for gitlab (displayed at top of repository view in web interface)? I mean only for SSH in clone urls.
For example I have my gitlab installation on git.example.com, but example.com also points to the same machine (different site). Can I change ssh clone urls from:
git clone git#git.example.com:user/repository
to:
git clone git#example.com:user/repositiory
but for http and https leave it with git.example.com?

Yes,
If you are using the omnibus package you can edit /etc/gitlab/gitlab.rb and add gitlab_rails['gitlab_ssh_host'] = 'example.host.com'
There is the equivalent option somewhere in gitlab.yml : ssh_host: example.host.com

Yes.
If your subdomain behaves the same way your actual domain does, it should not be a problem. If the subdomain points to the same IP, git or ssh for that matter should not bother.

Related

How do I force gitlab runner to use the host's domain name instead of ip address?

My company has a bitnami gitlab installation that we self-host. While I manage the gitlab installation, I am not an expert on it by any stretch. A few months back, I configured a project to use a gitlab runner in order to perform unit tests when the project is committed.
Today, when I pushed a commit, the gitlab runner tried to pull from the ip address using ssl. How do I tell it to pull the commit using the domain name?
I want it to use https://gitlab.ourcompany.com but it is using https://10.1.3.3
NOTE: not our real ip address or host name:
Getting source from Git repository
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/full-stack/apigw/.git/
fatal: unable to access 'https://10.1.2.3/full-stack/apigw.git/': SSL: no alternative certificate subject name matches target host name '10.1.2.3'
I found the answer after posting the question. Leaving both here for others.
It turns out that our gitlab.rb config file had the external_url set incorrectly. Here are the steps to change that:
/etc/gitlab/gitlab.rb
# other entries omitted for brevity
# was external_url 'https://10.1.2.3'
external_url 'https://gitlab.ourcompany.com'
Then reload your settings:
sudo gitlab-ctl reconfigure

clone private git repository with HTTP in cpanel

I want to integrate Cpanel with GitLab instance which its repositories are private and I can't use SSH because I don't have any access to the configuration of this instance and the Cpanel server (except the ssh keys section in Cpanel itself).
In Cpanel, the git section doesn't accept HTTP URLs for private git repositories and it suggests using SSH URLs instead but I can not.
I tried to use HTTP URL with username and password in URL but it prevents me to do this. like this:
https://USER:PASS#gitlab-instance.com/username/repository.git
anyone can help me to access the private git repository with SSH?
You should:
Add an ssh key
https://docs.gitlab.com/ee/gitlab-basics/create-your-ssh-keys.html
Access the repo via ssh
git#gitlab-instance.com:username/repository.git

GitLab Subdomain, Cloning via HTTPS Does Work. Cloning via SSH Does Not Work

I started to work for a new client and they have a GitLab subdomain to keep all their repositories. I applied my ssh key and gpg2 keys to their GitLab account. However, when I try to clone via ssh, I time out. But if I were to clone via HTTPS, everything works fine.
What step am I missing to get the ssh portion working?
Cloning via https does work.
https://gitlab.company_sub_domain.com/company/repository.git
Cloning via ssh does not work.
git#gitlab.company_sub_domain.com:company/repository.git
config file:
In case this may be of any help:
Try completing your ssh config file with
Host companysub
Hostname gitlab.company_sub_domain.com
User git
IdentityFile ~/.ssh/id_ed25519
(put the "Preferredauthentication publickey" part in Host *)
That way, your URL would become companysub, as in:
git clone companysub:company/repository.git
First, try an ssh -Tv companysub, to check if the key is recognized and working.

Change SSH repo url in GitLab

I have gitlab on my server. URL, for example: https://git.site.com
On project page I have similar URL for my repo:
How I can change path only for ssh repo path? I need IP address of my server, not URL
Change this in the /etc/gitlab/gitlab.rb
gitlab_rails['gitlab_ssh_host'] = 'gitssh.example.com'
and then run gitlab-ctl reconfigure
You should take a look at external_url configuration field: https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
If you're using Omnibus, you can also custom the SSH host: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/files/gitlab-config-template/gitlab.rb.template#L39

How to clone a git repository which is present on a remote linux server into windows

I have a git repository setup on a remote server XXX.XXX.XXX.XXX and want to clone the same in my windows environment. It's actually a webapp present under /var/www/html/Testsite. The git repo is created inside the Testsite folder.
I was hoping the command:
git clone http://XXX.XX.XX.XX/Testsite/mysite.git would work fine but it does not. Please let me know how I can get the URL to configure and clone it into my environment.
However, with the local folder, I am easily able to clone the repository which works totally fine.
Thanks a lot.
You can't, without configuring your Apache in order to server git request.
The fact that your mysite.git is within Testsite doesn't make it accessible to git.
As shown in this config, you can define in a separate VirtualHost (so in a separate port, since you are already using port 80/443 on Testing) a config in order to call the git script able to interpret a git clone request:
ScriptAlias /hgit/ /path/to/git/libexec/git-core/git-http-backend/
SetEnv GIT_HTTP_BACKEND "/path/to/git/libexec/git-core/git-http-backend"
<Location /hgit>
...
</Location>
As for ssh, the right url would be:
git clone ssh://account#XX.XX.XX.XX/var/www/html/Testsite/mysite.git
And it would work only if you generate a public and private (non-passhrase protected at first), and publish the public key in the ~account/.ssh/authorized_keys.
Or the sshd (ssh daemon) on the server won't recognize you (hence the password request), and won't know where "Testing/" is.

Resources