SSH won’t automatically start at startup – a solution

Posted: 2010/06/24 in Linux

Problem: SSH won’t autostart

Circumstance: New installation of Ubuntu 10.04 (Lucid Lynx), desktop.  Using ufw (fun) and Samba.  Using OpenSSH.  Setup is pretty normal: using port 22 and another.

Looked all over the web only to find all kinds of possible problems.  I first tried adding SSH to the /etc/rc?.d directories (rc5 and rc3):

cd /etc/rc3.d
ln -s ../init.d/ssh SS99ssh

Reboot… no dice.  So I searched (grep’d) /var/log/auth.log and saw that my server was not ‘binding’ to the address I had designated using the ListenAddress directive in /etc/ssh/sshd_config

cat /etc/ssh/sshd_config | grep ListenAddress
ListenAddress 192.168.0.2

cat /var/log/auth.log | grep sshd
Jun 24 ….. sshd[xxxx]:  fatal: Cannot bind any address
Jun 24 ….. sshd[xxxx]:  error: Bind to port 22 on 192.168.0.2 failed: Cannot assign requested address

Hmm… read, search, read, search…  Finally came across a solution to my situation.  I decided to NOT use ListenAddress.  I simply commented out that line and rebooted. It worked!  Now, I get the following output:

cat /var/log/auth.log | grep sshd
Jun 24 ….. sshd[xxxx]:  Server listening on 0.0.0.0 port 22

Upon further searching, I found that the OS didn’t know it was at 192.168.0.2 until after sshd had tried to start. This is evidenced by the fact that if I leave the ListenAddress active, sshd does not autostart but I can get it to start-up from the command line (sudo service ssh start) with no problem.  The auth.log output says ‘Server listening on 192.168.0.2 port 22’

I’m pretty sure there’s a way to get the OS to know what IP it is before sshd tries to initialize, but I haven’t figured that out yet… maybe soon (if I get the time).

Advertisements
Comments
  1. Alexander says:

    auto ethX
    iface ethX inet dhcp
    up service ssh start

    https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/216847

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