Cannot push git to remote repository: (SSH error)

15,420

Solution 1

Connection refused is a TCP error message saying that that server isn't running a service on that port. In this case, perhaps heroku.com's SSH server wasn't running.

If you haven't given them your key, or you use the wrong private key, ssh will say something like this:

frank@roke$ ssh [email protected]
Permission denied (publickey).

frank@roke$ ssh -i ~/.ssh/roke-frank.priv [email protected]
Permission denied (publickey).

(And the above messages indicate that right now heroku's SSH server is indeed running.)

Since you're not able to connect to the same server to which I can, perhaps there's a firewall issue. Are you behind a NAT? Does your gateway permit connections to port 22 on remote machines?

That machine runs a web server too, so try telnet heroku.com 80 to see if you can connect to that machine at all.

Solution 2

It seems ssh-server wasn't working or host was offline. I think it was temporally trouble.

I'm trying now:

telnet heroku.com 22
Trying 174.129.212.2...
Connected to heroku.com (174.129.212.2).
Escape character is '^]'.
SSH-2.0-OpenSSH_5.1p1 Debian-5pgsql1

Anyway you can diagnose doing ssh -v [email protected] (or -vv)

Share:
15,420
Matt H.
Author by

Matt H.

Updated on June 28, 2022

Comments

  • Matt H.
    Matt H. almost 2 years

    When I attempt to push to my heroku.com remote git repository, i get this message:

    ssh: connect to host heroku.com port 22: Connection refused
    

    I can easily work with my repository on github with the same ssh key.

    Entering:

    $ssh [email protected]    #outputs: success message
    $ssh [email protected]    #outputs: ssh: connect to host heroku.com port 22: Connection refused
    

    I'm on Mac OS 10.6. And I'm very clueless slowly learning!

    UPDATE:

    $telnet heroku.com 22
    

    gives this output:

    Trying 75.101.145.87...
    telnet: connect to address 75.101.145.87: Connection refused
    Trying 75.101.163.44...
    telnet: connect to address 75.101.163.44: Connection refused
    Trying 174.129.212.2...
    telnet: connect to address 174.129.212.2: Connection refused
    telnet: Unable to connect to remote host
    
  • Matt H.
    Matt H. over 13 years
    sorry, see updated post. i'm new to ssh in general. what I mean is i just configured an ssh key for the first time.
  • Matt H.
    Matt H. over 13 years
    i ran the command $heroku keys:add /Users/<username>/.ssh/id_rsa.pub with success, but i'm still getting the connection error when i try $ssh [email protected]
  • user1025901
    user1025901 over 13 years
    Matt, try telnet heroku.com 22 to check that the service is actually running. You should see something like SSH-2.0-OpenSSH_5.1p1 Debian-5pgsql1
  • Matt H.
    Matt H. over 13 years
    So running "telnet heroku.com 22" is giving me an error (see updated post), contrasted with how running "telnet github.com 22" gives me the results you predicted (SSH-2.0-....etc.). Does that mean something is wrong on heroku.com's end?
  • user1025901
    user1025901 over 13 years
    Or something in the middle. See my edited answer for another debugging tip.
  • Matt H.
    Matt H. over 13 years
    telnet heroku.com 80 is successful...$ telnet heroku.com 80 Trying 75.101.163.44... Connected to heroku.com. ---- i am not behind a firewall, AND what's really weird is $ssh [email protected] has no issues.. (and if I run ssh -v [email protected], i can see that it is connecting at port 22)
  • Matt H.
    Matt H. over 13 years
    the result: OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009 \\ debug1: Reading configuration data /etc/ssh_config \\ debug2: ssh_connect: needpriv 0 \\ debug1: Connecting to heroku.com [75.101.163.44] port 22. \\ debug1: connect to address 75.101.163.44 port 22: Connection refused debug1: Connecting to heroku.com [174.129.212.2] port 22. debug1: connect to address 174.129.212.2 port 22: Connection refused debug1: Connecting to heroku.com [75.101.145.87] port 22. debug1: connect to address 75.101.145.87 port 22: Connection refused ssh: connect to host heroku.com port 22: Connection refused
  • user1025901
    user1025901 over 13 years
    Time to ask tcpdump. Try something like tcpdump -i <your interface> -vX -s1024 host heroku.com and port 22 and let's see the output.
  • Matt H.
    Matt H. over 13 years
    so i wasn't sure what to put for <your interface> (i know very little about networks). from a little googling, it looks like some options were en0, en1, fw0, and lo0. I tried with all these (i had to do 'sudo' to get anywhere with it). After hitting enter I would see tcpdump: listening on en1, link-type EN10MB (Ethernet), capture size 1024 bytes and then a flashing cursor. Nothing happens... If I press Ctl+C to exit, it displays: 0 packets captured / 0 packets received by filter / 0 packets dropped by kernel was any of that helpful? thank you SO much for your time
  • Matt H.
    Matt H. over 13 years
    one other thing, i connected to my neighbor's unsecure wifi, and had all the same problems. so this leads me to think the problem is either a) on my system, or b) with my ISP. ... but i still can't wrap my head around why I can SSH git github on port 22, but not heroku.
  • Matt H.
    Matt H. over 13 years
    @frank. Ok i'm getting a little more hang of these command line items. What I tried: $tcpdump -i en1 -vX -s1024 host heroku.com and port 22 in a second terminal window I ran ssh [email protected]... NOTHING happened in the tcpdump window. By contrast, when I tried ... host github.com and port 22, and ran $ssh [email protected], I got LOTS of output in the terminal.
  • Matt H.
    Matt H. over 13 years
    @frank, ok one last thing! The people at heroku's tech support got back to me and said I probably have peerguardian or something similar that is causing problems. (i have peerguardian installed but it isn't running at present). to quote them specifically, they said "Most of the time, we find users who have software that is blocking ec2/amazon." maybe that helps?
  • Matt H.
    Matt H. over 13 years
    I did some digging and found out that peerguardian had two processes runnning in System Profiler, even though the app wasn't running. I completely uninstalled PeerGuardian and re-ran telnet heroku.com 22. Success!
  • user1025901
    user1025901 over 13 years
    ssh -v won't help (in this case): as you can see, it's a TCP problem. Connection refused means that negotiating the SSH session hasn't even started.
  • binW
    binW almost 11 years
    This was happening to me as well. I was behind a corporate firewall and trying to push to heroku. Although I was using anonymous proxy (tor) but this still kept happening as ssh was not using the proxy to tunnel the traffic. I then used corkscrew to tunnel ssh traffic through the proxy and it worked fine.
  • littlepea
    littlepea almost 11 years
    I have the same problem... I cannot push my code for any of my applications. I cannot connect to heroku.com by SSH (port 22) to use git: gist.github.com/littlepea/5538265