PeterD
PeterD

Reputation: 123

Problem with Git: "ssh: connect to host gitlab port 22: connection refused"

i am writing my bachelors thesis at a company and got access to gitlab from the admin, but I am new to Git. I created a new project for my thesis. I already had a folder with some stuff on my computer. I used the following commands in the git bash (as recommended by gitlab):

git init
git remote add origin git@gitlab:USER/TITLE.git
git add [stuff]
git commit
git push -u origin master

Committing was successfull, but the last command created the error

"ssh: connect to host gitlab port 22: Connection refused fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists."

I tried to switch to port 443, because apparently, that is a thing.

ssh -T -p 443 [email protected]

That got me:

"The authenticity of host '[altssh.gitlab.com]:443 ([35.190.168.187]:443)' can't be established.
ECDSA key fingerprint is [...].
Are you sure you want to continue connecting (yes/no/[fingerprint])?"

After typing yes:

"Warning: Permanently added '[altssh.gitlab.com]:443,[35.190.168.187]:443' (ECDSA) to the list of known hosts.
[email protected]: Permission denied (publickey)."

When going back to port 22, the connection timed out. The error after the push command is still the same.

According to canyouseeme.org, the ports 22 and 443 are not open.

I also tried to make new rules for the ports in the windows defender firewall menu.

Still the same error. I would really appreciate any help or ideas from you :)

Peter

Upvotes: 4

Views: 17870

Answers (4)

zhuziyi
zhuziyi

Reputation: 865

My answer is only a possibility, please don't point the objection!

I think the port is disabled by the administrator. It is recommended to contact the Gitlab system administrator。**

strong textConfigure enabled Git access protocols

With GitLab access restrictions, Administratorcan select the protocols users can use to communicate with GitLab. Disabling an access protocol does not block port access to the server itself. The ports used for the protocol, SSH or HTTP(S), are still accessible. The GitLab restrictions apply at the application level.

To specify the enabled Git access protocols:

  1. Sign in to GitLab as a user with Administrator access level.
  2. On the top bar, select Menu > Admin.
  3. On the left sidebar, select Settings > General.
  4. Expand the Visibility and access controls section.
  5. Select the desired Git access protocols:
  • Both SSH and HTTP(S)
  • Only SSH
  • Only HTTP(S)

Please select "Both SSH and HTTP(S)", and save changes.

Via:https://docs.gitlab.com/ee/user/admin_area/settings/visibility_and_access_controls.html

Upvotes: -1

Joel
Joel

Reputation: 1239

You may need to add your SSH key in your gitlab preferences.

Click on your head on the top right, then Preferences and SSH Keys.

If needed, more info on gitlab documentation.

Upvotes: 0

Alexander
Alexander

Reputation: 473

Check if you are not behind a VPN, I spent like half an hour before I thought about that.

Upvotes: 1

PeterD
PeterD

Reputation: 123

I solved it, it was not that hard. ssh does not work, everyone uses http here. I copied the wrong url from gitlab.

the command I had to use is:

git remote set-url origin http://gitlab/USER/PROJECT.git

Upvotes: 8

Related Questions