"Connection refused - connect(2) (Errno::ECONNREFUSED)" when pushing to the remote git server from gitlab
Solution 1
By default unicorn is configured to listening on 127.0.0.1:8080(/home/git/gitlab/config/unicorn.rb)
, so gitlab_url
needs to set as http://yourURL:8080/
Solution 2
I realize this is an old post, but for the general internet knowledge base.. Got this error in the latest version of gitlab setup, with a proxy virtual host in apache2, but also applies for nginx.
Ok, got the same issue - and here is how I solved it;
in /home/git/gitlab/config/unicorn.rb
find the lines
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64
listen "127.0.0.1:8080", :tcp_nopush => true
Change the last line to
listen "0.0.0.0:8080", :tcp_nopush => true
so it accepts connections not just from the local machine.
Solution 3
Again, in the hope that this might be useful to someone, somewhere; I had this same problem and none of the suggested solutions worked for me. Specifically, I do not care about HTTPS and my GitLab is not proxied behind Apache.
My gitlab-shell's config had gitlab_url: http://hostname:9999/
. My gitlab/config/unicorn.rb had listen "10.80.40.169:9999"
. So, I just changed the gitlab_url
to match unicorn.rb (gitlab_url: http://10.80.40.169:9999/
) and everything works.
Solution 4
After I executed (on the server with gitlab):
> pwd # just to get context
/home/git/gitlab
> sudo -u git -H /home/git/gitlab-shell/bin/gitlab-keys clear
> sudo -u git -H bundle exec rake gitlab:shell:setup RAILS_ENV=production
then removed git remote and added it back again (on the local server with git repo to push to gitlab):
> git remote remove origin
> git remote add origin ssh://[email protected]:12035/root/myproject.git
Then tried to push:
> git push --verbose -u origin master
Pushing to ssh://[email protected]:12035/root/myproject.git
Counting objects: 401, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (289/289), done.
Writing objects: 100% (401/401), 1.05 MiB | 98.00 KiB/s, done.
Total 401 (delta 127), reused 0 (delta 0)
To ssh://[email protected]:12035/root/myproject.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
updating local tracking ref 'refs/remotes/origin/master'
Now:
> cat /home/git/gitlab-shell/gitlab-shell.log
I, [2013-10-13T15:38:49.332477 #24935] INFO -- : gitlab-shell: executing git command <git-receive-pack /home/git/repositories/'/root/myproject.git'> for user with key key-1.
I, [2013-10-13T15:40:00.037092 #24958] INFO -- : Update head in project root/myproject.git to <master>.
I don't know what the real problem was here, but trying to investigate it step by step helped (first fixing the gitlab_url problem, then getting ssh working with the repo, and finally getting the git working properly). I hope these steps could help to solve some similar problems (e.g. named in the updates)
static
Updated on June 15, 2022Comments
-
static almost 2 years
I started gitlab with:
rvmsudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
When I create a new project, I get the remote repo url:
git remote add origin ssh://[email protected]:12035/root/my_project.git (so not the default 22 ssh port, but 12035)
So when I try to push it to the gitlab:
git push --verbose -u origin master
Then I get:
Pushing to ssh://[email protected]:12035/root/my_project.git /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:878:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED) from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:878:in `open' from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:878:in `block in connect' from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/timeout.rb:52:in `timeout' from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:877:in `connect' from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:862:in `do_start' from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:851:in `start' from /home/git/gitlab-shell/lib/gitlab_net.rb:62:in `get' from /home/git/gitlab-shell/lib/gitlab_net.rb:17:in `allowed?' from /home/git/gitlab-shell/lib/gitlab_shell.rb:60:in `validate_access' from /home/git/gitlab-shell/lib/gitlab_shell.rb:23:in `exec' from /home/git/gitlab-shell/bin/gitlab-shell:16:in `<main>' fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
So I have two users: a normal one:
kai
and thegit
for gitlab. But thegitlab
user has no.ssh
directory. But I already added the ssh-key from the remote machine from where I am trying to push to the gitlab. The key is added to the~/.ssh/config
as:Host gitlab.mydomain.com User [email protected] # User Administrator IdentityFile ~/.ssh/gitlab_rsa
P.S.
already looked into all similar questions here related to the error. but either didn't not get the answers or they didn't help
Update:
the lines in the
/var/log/auth.log
for the lastgit push
attempt:Oct 13 06:53:04 80-69-77-159 sudo: kai : TTY=pts/2 ; PWD=/home/git/gitlab ; USER=root ; COMMAND=/usr/bin/less /var/log/auth.log Oct 13 06:53:04 80-69-77-159 sudo: pam_unix(sudo:session): session opened for user root by kai(uid=0)
So all the possible users appear there. What does it mean?
Update 2:
I checked the gitlab-shell with:
sudo -u git -H /home/git/gitlab-shell/bin/check
and got the same:
http.rb:878:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
I changed then the
gitlab_url
tohttps
inconfig.yml
:sudo -u git -H nano /home/git/gitlab-shell/config.yml gitlab_url: "http://gitlab.udesk.org/" -> gitlab_url: "https://gitlab.udesk.org/"
Now I get from the
sudo -u git -H /home/git/gitlab-shell/bin/check
:SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
What could be now the problem?
Update 3:
Then I changed the
self_signed_cert: false
toself_signed_cert: true
in/home/git/gitlab-shell/config.yml
.Now I get from the
sudo -u git -H /home/git/gitlab-shell/bin/check
:Check GitLab API access: OK Check directories and files: /home/git/repositories: OK /home/git/.ssh/authorized_keys: OK
But still cannot push:
Pushing to ssh://[email protected]:12035/root/my_project.git Access denied. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Update 4:
Now I noticed that the test ssh line now works:
> ssh -vT -p 12035 [email protected] debug1: Authentication succeeded (publickey). Authenticated to gitlab.mydomain.com ([x.x.x.x]:12035). debug1: channel 0: new [client-session] debug1: Requesting [email protected] debug1: Entering interactive session. debug1: Remote: Forced command. debug1: Remote: Port forwarding disabled. debug1: Remote: X11 forwarding disabled. debug1: Remote: Agent forwarding disabled. debug1: Remote: Pty allocation disabled. debug1: Remote: Forced command. debug1: Remote: Port forwarding disabled. debug1: Remote: X11 forwarding disabled. debug1: Remote: Agent forwarding disabled. debug1: Remote: Pty allocation disabled. debug1: Sending environment. debug1: Sending env LANG = en_US.UTF-8 debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0 Welcome to GitLab, Administrator! debug1: channel 0: free: client-session, nchannels 1 Transferred: sent 3264, received 3248 bytes, in 0.7 seconds Bytes per second: sent 4782.6, received 4759.2 debug1: Exit status 0
Update 5:
in the
/home/git/gitlab-shell/gitlab-shell.log
the corresponding line to thegit push --verbose -u origin master
is:W, [2013-10-13T15:18:05.276231 #24654] WARN -- : gitlab-shell: Access denied for git command <git-receive-pack '/root/myproject.git'> by user with key key-1.
What could be still the problem?