7

I have a cloud server from Digital Ocean that is hosting GitLab.

Whenever I try to create a repository and push it to GitLab, I am getting the following error :

ssh: connect to host localhost port 22: Connection refused
fatal: The remote end hung up unexpectedly

I am fairly new to git so I am confused why I keep getting this error. I also have generated and added my SSH key to GitLab. Here are the steps I take to create the repository (per GitLab's instruction):

mkdir test
cd test
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@idAddress
git push -u origin master

Any suggestions?

2 Answers 2

5

You can test your SSH key authentication with:

$ ssh -T [email protected]

Check that your public key is saved in your Gitlab profile, and make sure no newlines are present in the string. Then check that git is using your correct private key if you have more than one.

Also consider that Gitlab may require the repository to exist; the push won't create a new repo.

Sign up to request clarification or add additional context in comments.

1 Comment

After running your suggested command, I received the message Welcome to GitLab, JT!. Is this what I should receive if my public key is setup correctly?
1

localhost port 22: Connection refused

Means Git tried to connect to SSH (port 22) to your local host (localhost), and nothing was listening on that port — hence Connection refused.

You mention ipAddress in your setup, is it 127.0.0.1?

3 Comments

At first I had it as localhost because I didn't follow the proper installation instruction when initially setting up the server. However, I changed it to the IP address of the server and it still didn't work.
@JTWheeler, I mean, you cited localhost in the error message. It this still correct now? Or do you get a similar error message (connection refused on port 22), just for a different host? If yes, this means the SSH server isn't listening (it is it which serves connections on port 22). Otherwise check to be sure that your remote "origin" does not point to localhost but to the new IP address.
Correct, I still receive the same error (connection refused on port 22). I will double check that the remote origin does not point to localhost. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.