init: ssh respawning too fast, stopped

While looking at error messages on an Ubuntu box, here is one I noticed in /var/log/syslog :

init: ssh respawning too fast, stopped

To avoid this error appearing again, here is the workout :

Add the following line ListenServer 0.0.0.0 in your sshd configuration file. (/etc/ssh/sshd_config)

root@localhost:~#echo “ListenServer 0.0.0.0” >> /etc/ssh/sshd_config

Advertisements

5 thoughts on “init: ssh respawning too fast, stopped

  1. Maybe you could care to explain the problem, just giving a solution that works “just for you” isn’t enough I think.

    As describe in BertieB’s blog (http://blog.roberthallam.org/2010/06/sshd-not-running-at-startup/), the sshd service is started by init too early and the network hasn’t been fully configured yet.

    Therefor, the sshd process which seems to try to find an IP adress to listen to, fails (network not available) and stops.
    But the init process looks after it and restart it immediately.

    The sshd stops and restart again dozens of times until init decides not to restart it anymore.

    The solution you describe here is to listen to a special address which means “listen on every IPs that you can”. Thus, sshd starts and will be fully fonctionial when the networks is started, when you have an IP adress. Until then, it just listen to “everywhere it can” meaning nothing.

    A good workaround could be to modify the init script (/etc/init.d/ssh) and specify that sshd need the network to be operational:
    # Required-Start: $remote_fs $syslog $network
    instead of
    # Required-Start: $remote_fs $syslog

    That way, you should not have any error on startup. What I don’t like in you workaround is that it prevent some configuration where you only want to listen to ONE incoming IP (in case you have multiple IPs on one or more interfaces).

    Another workaround (bad in my opinion, but better than doing it manually) is to setup a cron task.
    $ crontab -e

    Then add:
    @reboot service ssh start

    Add a sleep before that command if you fear that network really take a long time to be setup:
    @reboot sleep 60 && service ssh start

    • Thanks for your comment and your solution. I think the best way is to make sure that the script configuring the network is launched before the one for sshd.
      Then, no further need for additional workaround.

    • Good point Jeremie, I’ll update my post. FWIW, in my case the ssh daemon is running on a LAN computer with one IP, which is why I didn’t mind it listening to anything going. However, this is clearly not optimal, so I’ll update.

      I’m not sure why sshd doesn’t require $network by default, but that’s another question…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s