ssh:连接到主机 gitlab.com 端口 22:网络无法访问

Lui*_*ipe 5 git ssh ssh-keys public-key gitlab

我正在尝试访问 Gitlab 服务器以在 Ubuntu 20.10 计算机中克隆存储库,但我总是收到消息:

ssh: connect to host gitlab.com port 22: Connection timed out
fatal: Could not read from remote repository.

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

Run Code Online (Sandbox Code Playgroud)

所以,我试图运行命令ssh -T git@gitlab.com,但我收到了消息:

ssh: connect to host gitlab.com port 22: Network is unreachable
Run Code Online (Sandbox Code Playgroud)

我已经在另一台装有 Ubuntu 20.04 的计算机上尝试过,它工作正常。

任何人都可以帮助我吗?

ai2*_*2ys 8

我遇到过同样的问题。我通过 ssh 连接到远程计算机(VPN 已打开,因为它位于公司内)。从远程计算机上,我尝试 git clone (ssh) 并收到以下错误消息:

git clone git@gitlab.com:<project-name>.git
Cloning into '<project-name>'...
ssh: connect to host gitlab.com port 22: Network is unreachable
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)

以下解决方案有效。我将以下内容添加到远程计算机的 ssh-config 中,如下所述:https: //about.gitlab.com/blog/2016/02/18/gitlab-dot-com-now-supports-an-alternate -git-plus-ssh-port/

Host gitlab.com
  Hostname altssh.gitlab.com
  User git
  Port 443
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/gitlab
Run Code Online (Sandbox Code Playgroud)

我现在可以毫无问题地从 GitLab git clone (ssh) 项目。


Von*_*onC 5

我永远无法在工作环境中对任何公共 Git 存储库托管服务(github.com、gitlab.com 等)使用 SSH URL。

如果其他服务 ( ) 仍然存在问题ssh -Tv git@github.com,则不允许您使用 SSH URL。使用 HTTPS URL。

但是,如果在同一网络上,另一台服务器确实可以工作,则请仔细检查特定计算机的防火墙规则。其中一个可能会阻止 SSH,而另一个则不会。
( ufw status verbose)


小智 5

如果您现在无法使用 ssh,您可以使用 HTTPS 代替:

git remote set-url origin <Clone HTTPS address>
Run Code Online (Sandbox Code Playgroud)