7

I using Starbucks wifi and I get the following when trying to push to a gitlab.com repo:

  $ git push origin master
  ssh: connect to host gitlab.com port 22: Connection refused
  fatal: Could not read from remote repository.

I tried adapting a workaround for GitHub: Github (SSH) via public WIFI, port 22 blocked by adding the following to ~/.ssh/config

 Host gitlab.com
        Hostname gitlab.com
        Port 443

But that doesn't work as I get this error:

 $ git push origin master
 ssh_exchange_identification: Connection closed by remote host
 fatal: Could not read from remote repository.

 Please make sure you have the correct access rights
 and the repository exists.

I there a workaround that will allow me to push to GitLab.com using port 443?

Community
  • 1
  • 1
Elijah Lofgren
  • 1,437
  • 3
  • 23
  • 39
  • 1
    Since February 2016, you can keep pushing in ssh to GitLab, **even if port 22 is blocked**! See [my answer below](http://stackoverflow.com/a/35500957/6309) – VonC Feb 19 '16 at 08:48

3 Answers3

9

Since February 2016, you are no longer required to switch to https.
You can push to GitLab in ssh on... port 443 (the port usually reserved for https transaction)

See "GitLab.com now supports an alternate git+ssh port"

GitLab.com runs a second SSH server that listens on the commonly used port 443, which is unlikely to be firewalled.

All you have to do is edit your ~/.ssh/config and change the way you connect to GitLab.com.
The two notable changes are Hostname and Port:

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

[ You might have to change your remote origin url:

git remote set-url origin altssh.gitlab.com:user/myrepo.git

]

The first time you push to altssh.gitlab.com you will be asked to verify the server’s key fingerprint:

The authenticity of host '[altssh.gitlab.com]:443 ([104.208.154.249]:443)' can't be established.
ECDSA key fingerprint is SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw.
Are you sure you want to continue connecting (yes/no)?

That’s only normal since you are connecting to the new loadbalancer. If you watch closely, the key fingerprint is the same as in GitLab.com.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Thanks to @oleg-gopkolov for giving me the hint to try defining the origin differently! It turns out ssh port 443 didn't work but https did as per below.

How to switch origin to https so that pushing to gitlab.com works while on on Starbucks wifi

Here are the commands to switch to https (if you had experimented with other changes and your local is out of date like mine was you will also need to follow Cannot push to GitHub - keeps saying need merge ):

git remote remove origin
git remote add origin https://gitlab.com/your_username/your_repo.git
git push --set-upstream origin master

If you want to do some testing on a fresh checkout

It turns out that using the https checkout option does work. So provided you don't mind a fresh checkout, you can run this on Starbucks wifi:

git clone https://gitlab.com/your_username/your_repo.git

Then to test committing you can edit README.md and then run:

  git commit README.md
  git push

If you want to confirm that SSH GitLab access doesn't work on Starbucks wifi

To confirm that SSH cloning does not work at Starbucks you can run one of the following 3 commands:

git clone git@gitlab.com:your_username/your_repo.git
git clone git@gitlab.com:443/your_username/your_repo.git
git clone ssh://gitlab.com:443your_username/your_repo.git

And for each one you will get an error like this:

Cloning into 'your_repo'...
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.
Community
  • 1
  • 1
Elijah Lofgren
  • 1,437
  • 3
  • 23
  • 39
1

Define your remote such that it uses port 443

git remote add origin ssh://some.host:443/path/to/repo.git

Oleg Gopkolov
  • 1,684
  • 10
  • 17
  • I had trouble adding so I tried cloning and got an error - I'm guessing gitlab doesn't support 443 for ssh?: git clone ssh://gitlab.com:443/elijahlofgren/second-meteor-tutorial.git Cloning into 'second-meteor-tutorial'... ssh_exchange_identification: Connection closed by remote host fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. – Elijah Lofgren Sep 19 '15 at 15:03
  • Here's error I get when trying to push after adding the ssh origin: git push origin remote error: src refspec remote does not match any. error: failed to push some refs to 'ssh://gitlab.com:443/elijahlofgren/second-meteor-tutorial.git' – Elijah Lofgren Sep 19 '15 at 15:06
  • Wow, apparently although I can browse https://gitlab.com/ I can't ping it (perhaps Starbucks blocks pings?): ping gitlab.com PING gitlab.com (52.21.36.51): 56 data bytes Request timeout for icmp_seq 0 Request timeout for icmp_seq 1 – Elijah Lofgren Sep 19 '15 at 15:08
  • I have entered the output of cat ~/.ssh/id_rsa.pub at https://gitlab.com/profile/keys (or does having public key from gitlab.com mean something else, sorry I'm a bit of a beginner in this area). One interesting thing is I tried using my phone as hotspot to ping gitlab.com and it still fails. Thanks for trying to help with this! – Elijah Lofgren Sep 19 '15 at 15:22
  • @elijahlofgren Unfortunately I don't have this keys and can't check solution from my computer. – Oleg Gopkolov Sep 19 '15 at 15:31
  • @elijahlofgren Do you have other computer in the internet with external ip address ???? – Oleg Gopkolov Sep 19 '15 at 15:58
  • I don't have one that I can readily test with. I did find a workaround which I posted in an answer above. I upvoted your answer because it helped me find the solution. Thank you so much for your help! – Elijah Lofgren Sep 19 '15 at 16:04