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

Viewed 26141

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?

8 Answers

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)

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

git remote set-url origin <Clone HTTPS address>

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.

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.

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.

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.

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!

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.

Related