GitLab (SSH) via public WIFI, port 22 blocked

2019-02-18 03:35发布

问题:

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?

回答1:

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.



回答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.


回答3:

Define your remote such that it uses port 443

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



标签: ssh wifi gitlab