1

When I tried to log into my remote Ubuntu server today, I got:

ssh: connect to host <ip> port 22: Connection refused

So I rebooted the server, thinking sshd might have crashed.

After the boot I could connect via ssh, but after 1 or 2 minutes the server closed the connection:

Connection to <ip> closed by remote host.

Trying to reconnect, the server refuses the connection again.

Manually doing

/etc/init.d/sshd restart

didn't help, /etc/hosts.deny seems ok.

This is extremely annoying, since I have so little time to diagnose or fix the problem. Help or ideas are greatly appreciated!

4
  • 2
    How about a firewall that starts some time after boot? Does that block your connection? Is the sshd still listening on port 22 when you can't connect? Are there any log messages in the system log?
    – mailq
    Jul 20, 2011 at 16:06
  • Please take a brief excursion through your log files looking for things that seem abnormal or indicative of a problem -- We will be better able to help you with that information.
    – voretaq7
    Jul 20, 2011 at 16:27
  • I did an grep -ir ssh /var/log/* and found nothing interesting or related, but some people seem to be spamming my ssh like crazy (ddos style) trying to log in as root (the events are usually some weeks apart) WTF! Jul 20, 2011 at 17:02
  • @Anselm that's normal, sadly: serverfault.com/q/244614/65089 Jul 20, 2011 at 19:51

1 Answer 1

1

When the error message is "Connection refused" it means that sshd is no longer listening on your ssh port. If it was your firewall, you would have received a "Timeout". In either case, do ssh with verbose option and see exactly at what step the connection is getting dropped.

6
  • Connection refused is likely to be iptables as well, if the "-j reject" is used.
    – Rilindo
    Jul 20, 2011 at 21:01
  • Thats a good catch :)
    – SparX
    Jul 21, 2011 at 1:11
  • sparx.me: with the verbose option ssh gives me: OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Connecting to <url> [<ip>] port 22. debug1: connect to address <ip> port 22: Connection refused ssh: connect to host <url> port 22: Connection refused Jul 21, 2011 at 10:40
  • Rilindo: I will find out what -j reject does for iptables and report back (I'm a noob admin so I have to learn) Jul 21, 2011 at 10:43
  • Can you connect locally inside the server itself? Like this: ssh localhost
    – Rilindo
    Jul 21, 2011 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .