在公共无线网络上使用GitLab(SSH),22端口被阻止

7

我正在使用星巴克的WiFi,当我尝试向gitlab.com仓库推送代码时,出现以下错误信息:

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

我尝试适应GitHub的解决方法:Github (SSH) via public WIFI, port 22 blocked,通过添加以下内容到~/.ssh/config来解决问题。

 Host gitlab.com
        Hostname gitlab.com
        Port 443

但是这并不起作用,因为我会收到以下错误信息:
 $ 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.

有没有一种方法可以绕过限制,使用443端口推送到GitLab.com?

1
自2016年2月起,即使端口22被阻止,您仍然可以通过ssh推送到GitLab!请参见下面的我的答案 - VonC
3个回答

10
自2016年2月起,您不再需要切换到https。您可以在ssh上将内容推送到GitLab...端口443(通常用于https交易的端口)。
请参见“GitLab.com现在支持备用git+ssh端口”。 GitLab.com运行第二个SSH服务器,监听通常使用的443端口,这个端口不太可能被防火墙阻止。 只需编辑您的~/.ssh/config并更改连接到GitLab.com的方式即可。两个值得注意的更改是主机名和端口:
Host gitlab.com
  Hostname altssh.gitlab.com
  User git
  Port 443
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/gitlab

你可能需要更改远程源URL:
git remote set-url origin altssh.gitlab.com:user/myrepo.git

]

第一次推送到altssh.gitlab.com时,您将被要求验证服务器的密钥指纹:
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)?

这很正常,因为您正在连接到新的负载均衡器。如果您仔细观察,key fingerprint is the same as in GitLab.com

2

感谢@oleg-gopkolov给我提示尝试不同方式定义起点! 结果表明ssh端口443无法工作,但https却可以。

如何将起点切换为https以便在星巴克wifi上推送到gitlab.com

以下是切换为https的命令(如果您已经尝试了其他更改并且本地过时,就像我的一样,您还需要遵循无法推送到GitHub-一直说需要合并):

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

如果您想在全新的检出上进行测试

事实证明,使用https检出选项确实可行。因此,只要您不介意进行全新的检查,就可以在星巴克wifi上运行此操作:

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

然后,为了测试提交,您可以编辑README.md文件,然后运行:

  git commit README.md
  git push

如果您想确认在星巴克Wi-Fi下无法访问SSH GitLab

要确认在星巴克无法进行SSH克隆,您可以运行以下三个命令之一:

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

对于每一个错误,您将会得到类似于这样的错误信息:

Cloning into 'your_repo'...
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

1
定义您的远程仓库,使其使用443端口:
``` git remote add origin ssh://some.host:443/path/to/repo.git ```

我在添加时遇到了问题,所以尝试了克隆并出现了错误 - 我猜测gitlab不支持443用于ssh吗?:git clone ssh://gitlab.com:443/elijahlofgren/second-meteor-tutorial.git 正在克隆 'second-meteor-tutorial'... ssh_exchange_identification: 远程主机关闭连接 fatal: 无法从远程存储库读取。请确保您拥有正确的访问权限并且存储库存在。 - Elijah Lofgren
当我添加ssh origin后尝试推送时,出现以下错误:git push origin remote 错误:src refspec remote与任何内容都不匹配。 错误:无法将某些引用推送到'ssh://gitlab.com:443/elijahlofgren/second-meteor-tutorial.git'。 - Elijah Lofgren
哇,虽然我可以浏览https://gitlab.com/网站,但我无法ping它(可能是星巴克阻止ping吧?):ping gitlab.com PING gitlab.com (52.21.36.51): 56 data bytes 请求超时 icmp_seq 0 请求超时 icmp_seq 1 - Elijah Lofgren
我已经在https://gitlab.com/profile/keys输入了cat ~/.ssh/id_rsa.pub的输出(或者从gitlab.com获取公钥意味着其他什么,抱歉我在这个领域有点新手)。有趣的是,我尝试使用手机热点ping gitlab.com,但仍然失败。感谢您的帮助! - Elijah Lofgren
我没有一个可以立即测试的。我找到了一个解决方法,已经在上面的答案中发布了。我点赞你的答案,因为它帮助我找到了解决方案。非常感谢你的帮助! - Elijah Lofgren
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接