Ssh – Intermittent ssh “Connection refused” errors

connectionsshsvn

Recently, while using svn+ssh on Mac OSX, usually after a few svn operation, I usually get in a state where I only get "Connection refused" errors from any svn command. At this point, any operation using ssh (ssh username@hostname) will result a "Connection refused" error. I then have to wait for a few minutes until it starts working again.

Here is what I have looked into so far:

  • Asked hosting provider for ssh particularities (dedicated ip, port 22 to open). Everything is fine according to them.
  • Checked on a different machine, different operating system (Windows XP using putty). Same result
  • No firewalls are running.
  • Port 22 is not blocked by my router.
  • If I have a ssh connection on the server when the connection refused message start appearing. Using that connection, shh localhost will work.

Is there anything else that could be used to help find the source of the problem?

Best Answer

I'd leave an SSH connection open for the next time it starts happening, and then run a tcpdump on the server to see what's happening to the packets. If they're not turning up on the server, then they're being misdirected by the hosting provider or somewhere further up; if they are arriving then something local is refusing the connection. It could be that SSH is actually dying -- check netstat -ltnp for something listening on port 22.

The fact that everything comes back after a few minutes suggests that it could even be some sort of SSH rate-limiting in the firewall (designed to stop brute-force attacks) that's getting in the way ("normal" use of SSH wouldn't generate many SSH connections, but SVN does a lot of SSHing). If that's the case, make sure everyone's got nice strong passwords (or just turn them off and use keys) and then turn the stupid brute-force protection off.