10

I'm trying to reach the Gitlab server to clone a repo in a Ubuntu 20.10 computer, but I always get the message:

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.

So, I've tried to run the command ssh -T git@gitlab.com, but I've got the message:

ssh: connect to host gitlab.com port 22: Network is unreachable

I've tried in another computer with Ubuntu 20.04 and it worked.

Anyone can help me with this?

LuisFelipe
  • 135
  • 1
  • 1
  • 8

8 Answers8

8

I had the same issue. I am connected to a remote machine via ssh (VPN turned on because it is located in the company). From the remote machine I tried to git clone (ssh) and got the following error message:

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.

The following solution worked. I added the following to the ssh-config of the remote machine, which was described here: 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

I am now able to git clone (ssh) projects from GitLab without any problems.

ai2ys
  • 1,151
  • 10
  • 21
5

I would never be able to use SSH URL for any public Git repository hosting service (github.com, gitlab.com, ...) in a work environment.

If the issue persists with other services (ssh -Tv git@github.com), then SSH URLs are not allowed for you. Use an HTTPS URL.

But if on the same network, another server does work, then double-check the firewall rules for your particular machine. One might block SSH, while the other not.
(ufw status verbose)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I've enabled ssh and port 22 and it stills the same. On github it works properly. The other computer is not on the same network, unfortunately, and the gitlab url is not the same. To check the network, I've tried with VPN on and off, didn't worked. – LuisFelipe Dec 15 '20 at 12:06
  • @LuisFelipe So your machine, you can contact github through SSH, but not gitlab.com? – VonC Dec 15 '20 at 12:08
  • Basically, yes. But I need both, one is for my job repo and the other are for personal and other jobs. – LuisFelipe Dec 15 '20 at 13:10
  • @LuisFelipe Can you ping gitlab.com? – VonC Dec 15 '20 at 13:36
  • Gitlab pinging normally. The gitlab URL that I need is the corporative one, in gitlab domain. – LuisFelipe Dec 15 '20 at 13:42
  • @LuisFelipe Do you mean it is not gitlab.com? – VonC Dec 15 '20 at 13:43
  • I was able to connect to gitlab.com after executing the command in this answer and accepting the fingerprint question. – Max J Mar 24 '21 at 10:34
  • @MaxJ OK: SSH is not blocked in your working environment (it is certainly blocked in mine) – VonC Mar 24 '21 at 10:36
4

If you can't use ssh right now,You can use HTTPS instead with:

git remote set-url origin <Clone HTTPS address>
Mevil
  • 41
  • 1
  • 2
2

There are a couple possible reasons for this:

1.) You are on a network which blocks traffic to port 22. Trying your connection from another network or device would be the best way to quickly test for this.

2.) The ssh service on your droplet is not running.

Solutions:

  1. You can change the port that your ssh service listens on in the file /etc/ssh/sshd_conf or you can use other network to test this problem solution.
  2. Configure your SSH key agian.
Md. Shafiqul Islam
  • 196
  • 1
  • 4
  • 9
2

I was happily pushing and pulling to my (private) gitlab repo via SSH (Ubuntu with WSL2) until this error popped up. After about 5 minutes of trying to google the error, it just started working again!

If you've successfully pushed/pulled/cloned and confident its not a firewall issue, you might just need to go and make yourself a coffee and try again before losing hours on stackoverflow!

2

After days of searching and set up several times by delete .ssh file and set up again, I found the problem was with the network where certain websites where blocked from accessing, so I unblocked it in the network provider in safe filter like webs for "address hiding" or "hacking".

Then git clone and push works as usual.

Obsidian
  • 3,719
  • 8
  • 17
  • 30
1

I've figured it out, the server I've been trying to connect needs a proxy, which solved the problem. But I hope someone can get helped by this.

LuisFelipe
  • 135
  • 1
  • 1
  • 8
0

I meet the same problem, I could not connect to GitLab via SSH via the Windows PowerShell terminal. The solution was to use HTTPS to access GitLab through the built-in extension in the VScode editor.

Kotkoa
  • 5
  • 3