6

For the last couple of days I have been unable to push to the remote (gitlab), it has worked before this. I know this question has 10s of similar SO questions and perhaps an answer is somewhere in those. However I have been trying many of the suggested solutions - in vain.

  • When I push I get:

    ssh: connect to host gitlab.com port 22: Connection refused fatal: The remote end hung up unexpectedly

  • The local is on a constitutional server and many people here are using port 22 mostly for github with no problems. Is it possible that this is a firewall setting on my side that could be related to gitlab specifically? The administrator ensures that it is not a simple whitelist issue.

  • My gitlab url is as:

    origin git@gitlab.com:myname/myproject.git (fetch) origin git@gitlab.com:myname/myproject.git (push)

  • I have tried to update the git-url with the alternative ssh format:

    origin ssh://git@gitlab.com/myname/myproject.git (fetch) origin ssh://git@gitlab.com/myname/myproject.git (push)

  • I have tried both port 22 and the alternative 443 - this is the ~/.ssh/config file:

    Host gitlab.com RSAAuthentication yes IdentityFile ~/.ssh/id_rsa

  • Alternative:

    Host gitlab.com Hostname altssh.gitlab.com User git Port 443 PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa

  • I have tried to use https connection (in vain).

  • Made new ssh keys (in vain).

I am lost with things to try and my branch is ahead of origin by a lot of commits. Am I missing something simple here to try out ?.

UPDATE

When removing ~/.ssh/config and issuing ssh -Tv git@gitlab.com it still does not work - I get:

OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to gitlab.com [52.167.219.168] port 22.
debug1: connect to address 52.167.219.168 port 22: Connection refused
ssh: connect to host gitlab.com port 22: Connection refused

UPDATE 2 So it turns out that our institutional server does not whitelist gitlab.com because they - in contrast to, say, github.com, does not provide an official IP address range. My solution was to make a mount point from my workstation computer to the server containing my project, and then push/pull the git directory via the computer.

user3375672
  • 3,728
  • 9
  • 41
  • 70

3 Answers3

6

Make sure there is no ~/.ssh/config file in your case: the default URL you mention should work without a config file.

And make sure the content of the ~/.ssh/id_rsa.pub is registered to your account.

Test that it is the case with:

ssh -Tv git@gitlab.com

If that does not work, it means either the ssh port is blocked, or ISP does not give access to the remote site.

It turns out the OP mentions the second case:

our institutional server does not whitelist gitlab.com because they - in contrast to, say, github.com, does not provide an official IP address range.
My solution was to make a mount point from my workstation computer to the server containing my project, and then push/pull the git directory via the computer.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • See update. BTW, why no config file in this setting ? – user3375672 Apr 07 '18 at 18:27
  • @user3375672 no config: it will interfere with the default URL. – VonC Apr 07 '18 at 19:36
  • @user3375672 Does it work with `ssh -Tv git@github.com`? If not, would https://about.gitlab.com/2016/02/18/gitlab-dot-com-now-supports-an-alternate-git-plus-ssh-port/ help? (I mentioned it in https://stackoverflow.com/a/35500957/6309) – VonC Apr 07 '18 at 19:38
  • No see my update. Connection still refused, but whether registered to my account i do not know if it tells. – user3375672 Apr 07 '18 at 19:40
  • @user3375672 it looks like the ssh ports are blocked from your workstation somehow (even though it was working before) Especially if github.com does not work either. – VonC Apr 07 '18 at 19:41
1

If you get the error..

ssh: connect to host git.my-host.com port 22: Connection refused
fatal: Could not read from remote repository.

..then you might be able to solve it by deleting the entry for the IP of your GitLab host in

~/.ssh/known_hosts
0x4a6f4672
  • 27,297
  • 17
  • 103
  • 140
0

1.) Add the Host known in nano ~/.ssh/config

Host git.company.com
HostName <ip address of git> 
Port 222

2.) Run this command to generate and pair pub and priv key.

ssh-keygen -t ed25519 -C "<comment>"

3.) Copy content of ~/.ssh/id_rsa.pub

4.) Paste it in by generating new SSH keys in your gitlab account, specify title to where you will use it to add identification of the generated SSH Key.

Try to clone a project now on your gitlab repo.