title: "Connection refused - connect(2) (Errno::ECONNREFUSED)" when pushing to the remote git server from gitlab
body: <p>I started gitlab with:</p>
  
  <pre><code>rvmsudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  </code></pre>
  
  <p>When I create a new project, I get the remote repo url:</p>
  
  <pre><code>git remote add origin ssh://git@gitlab.mydomain.com:12035/root/my_project.git
  
  (so not the default 22 ssh port, but 12035)
  </code></pre>
  
  <p>So when I try to push it to the gitlab:</p>
  
  <pre><code>git push --verbose -u origin master
  </code></pre>
  
  <p>Then I get:</p>
  
  <pre><code>Pushing to ssh://git@gitlab.mydomain.com: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 `&lt;main&gt;'
  fatal: Could not read from remote repository.
  
  Please make sure you have the correct access rights
  and the repository exists.
  </code></pre>
  
  <p>So I have two users: a normal one: <code>kai</code> and the <code>git</code> for gitlab. But the <code>gitlab</code> user has no <code>.ssh</code> 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 <code>~/.ssh/config</code> as:</p>
  
  <pre><code>Host gitlab.mydomain.com
          User admin@local.host
          # User Administrator
          IdentityFile ~/.ssh/gitlab_rsa
  </code></pre>
  
  <h1>P.S.</h1>
  
  <p>already looked into all similar questions here related to the error. but either didn't not get the answers or they didn't help</p>
  
  <h1>Update:</h1>
  
  <p>the lines in the <code>/var/log/auth.log</code> for the last <code>git push</code> attempt:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>So all the possible users appear there. What does it mean?</p>
  
  <p>Update 2:</p>
  
  <p>I checked the gitlab-shell with:</p>
  
  <pre><code>sudo -u git -H /home/git/gitlab-shell/bin/check
  </code></pre>
  
  <p>and got the same:</p>
  
  <pre><code>http.rb:878:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
  </code></pre>
  
  <p>I changed then the <code>gitlab_url</code> to <code>https</code> in <code>config.yml</code>:</p>
  
  <pre><code>sudo -u git -H nano /home/git/gitlab-shell/config.yml
  
  gitlab_url: "http://gitlab.udesk.org/" -&gt; gitlab_url: "https://gitlab.udesk.org/"
  </code></pre>
  
  <p>Now I get from the <code>sudo -u git -H /home/git/gitlab-shell/bin/check</code>:</p>
  
  <pre><code>SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
  </code></pre>
  
  <p>What could be now the problem?</p>
  
  <h1>Update 3:</h1>
  
  <p>Then I changed the <code>self_signed_cert: false</code> to <code>self_signed_cert: true</code> in <code>/home/git/gitlab-shell/config.yml</code>. </p>
  
  <p>Now I get from the <code>sudo -u git -H /home/git/gitlab-shell/bin/check</code>:</p>
  
  <pre><code>Check GitLab API access: OK
  Check directories and files: 
      /home/git/repositories: OK
      /home/git/.ssh/authorized_keys: OK
  </code></pre>
  
  <p>But still cannot push:</p>
  
  <pre><code>Pushing to ssh://git@gitlab.mydomain.com: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.
  </code></pre>
  
  <h1>Update 4:</h1>
  
  <p>Now I noticed that the test ssh line now works:</p>
  
  <pre><code>&gt; ssh -vT -p 12035 git@gitlab.mydomain.com
  
  debug1: Authentication succeeded (publickey).
  Authenticated to gitlab.mydomain.com ([x.x.x.x]:12035).
  debug1: channel 0: new [client-session]
  debug1: Requesting no-more-sessions@openssh.com
  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 eow@openssh.com 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
  </code></pre>
  
  <h1>Update 5:</h1>
  
  <p>in the <code>/home/git/gitlab-shell/gitlab-shell.log</code> the corresponding line to the <code>git push --verbose -u origin master</code> is:</p>
  
  <pre><code>W, [2013-10-13T15:18:05.276231 #24654]  WARN -- : gitlab-shell: Access denied for git command &lt;git-receive-pack '/root/myproject.git'&gt; by user with key key-1.
  </code></pre>
  
  <p>What could be still the problem?</p>