Why some gitlab project clone with SSH do not have SSH schema? - gitlab

when I watch a tutorial:
when clone a project with SSH, it shows git#xxx like below:
but when I use my Gitlab in practice:
there have schema ssh://, what's the difference?
ssh://git#gitlab.demo.com:222/xxx

That depend on how the custom SSH URL was set for your GitLab instance:
gitlab-ctl show-config | gitlab_ssh_host
The default one uses the default SSH URL scheme, using '/' only.
But you can set it to a SCP-style URL, without ssh://, and using a ':' between domain and URL path.
To change it:
Edit /etc/gitlab/gitlab.rb
Search for gitlab_rails['gitlab_ssh_host'] = 'your.hostname.here'
Update the hostname value and run a gitlab-ctl reconfigure afterwards.

Related

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

Gitlab 'fatal: repository '...' not found' - unable to push to a newly created project

Can anyone spot what I could possibly be doing wrong? You can browser zoom in to see image details.
This is a fresh account, new project, owner of group and I am simply unable to push (HTTPS) following instructions provided.
When adding the remote URL to the initial configuration, instead of using the URL that Gitlab gives you, try adding the following URL instead and replace the details below as mentioned, to reflect your info & your project info:
REMOTE URL FORMAT:
https://YOUR_USER_NAME:PASSWORD#gitlab.com/YOUR_USER_NAME/YOUR_PROJECT_NAME.git/
REPLACEMENTS IN THE ABOVE URL:
YOUR_USER_NAME - Replace this with your gitlab username
PASSWORD - Replace this with your gitlab password
YOUR_PROJECT_NAME - Replace this with your gitlab project name (whatever is generated for you)
I create a small site to fix really quick this issue. gitlab fix remote
While Adding Your URL make sure you add your username like this
https://username#gitlab.com/path_of_repository.git
and also .git at the end is not to be missed
try to /profile/keys and add new key of server in GitLab
In your GitLab got to: /help/ssh/README
SSH keys
An SSH key allows you to establish a secure connection between your computer and GitLab.
In my case for HTTPS-URL, it was not working
So I tried using it with SSH
First open command prompt in administrator mode then enter the following command to generate SSH key:
ssh-keygen -t rsa -b 4096 -C “<my key name>”
Then go to the location where this key is saved 'In my case (C:\Users\your_username\.ssh)' and open id_rsa.pub and copy its content.
Then go to GitLab create a new SSH key and add this copied content to your SSH key.
After that try cloning using SSH-URL

How can a GitLab ssh url show a non-default user?

I have a GitLab installation, but it is installed under a different user to the default 'git'.
On project pages, users are instructed to use the following URL for ssh:
git#host:user/project.git
How do I change this to show the new username?
Try and modify/uncomment the lines regarding ssh use in gitlab.yml
# Uncomment and customize if you can't use the default user to run GitLab (default: 'git')
# user: git
The initializer is supposed to use that setting when computing the ssh url for repos.
See "config/initializers/1_settings.rb#L12-L18"
def build_gitlab_shell_ssh_path_prefix
if gitlab_shell.ssh_port != 22
"ssh://#{gitlab_shell.ssh_user}##{gitlab_shell.ssh_host}:#{gitlab_shell.ssh_port}/"
else
"#{gitlab_shell.ssh_user}##{gitlab_shell.ssh_host}:"
end
end

Change SSH host for cloning

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.

Resources