ssh server service won't start on Ubuntu 18.04 after reboot

I've a VPS with Ubuntu 18.04Lts on Google Cloud.

On every reboot, I've to start the ssh daemon service either by service ssh(d) start or systemctl start ssh(d) (both ssh and sshd work the similar way and start the needed service.

But its very difficult and cumbersome to start the server on serial ports and then start the ssh service on the server. I've tried the following ways to configure the service to start behind it. I've found all the ways in diff articles found thru google or on Stack answers (I don't know the reasons/logics behind them). I did them one by one, mostly without first undoing the prev one.

  1. Tried installing and reinstalling the openssh-server.
  2. Ran this command: sudo systemctl enable sshd.service
  3. Ran this command: systemctl enable sshd
  4. Ran this command: sudo update-rc.d sshd defaults
  5. Ran this command: systemctl enable ssh.socket
  6. Checked that symbolic link of /etc/rc*.d/S**ssh are there
  7. Commenting out the specific ListenAddress directive and adding ListenAddress 0.0.0.0 to let sshd listen on any address in the file : /etc/ssh/sshd_config.
  8. Edited this line # Required-Start: $remote_fs $syslog to this line # Required-Start: $remote_fs $syslog $network in the file /etc/init.d./ssh (to stop sshd from starting before the network is ready).
  9. Added this line: sshd & to the (end of) file /etc/init.d/rc.local.
  10. Edited this file: /etc/rc.local and added this line: /etc/init.d/ssh start
  11. Edited the /etc/ssh/sshd_config file and in it, change Port to 2222. Also set the PasswordAuthentication to yes.
  12. Added/tried these lines in root's crontab file: @reboot mkdir -p -m0755 /var/run/sshd && systemctl restart ssh.service. Didn't work, then tried this @ systemctl restart ssh.service. then commented out this also, And tried this: @reboot service ssh start. But again, commented out this one and tried this last one: @reboot sleep 15 && /bin/systemctl restart sshd.

Even after trying these 15 solutions, the ssh service still doesn't start upon reboot. Kindly do help.

2

3 Answers

open /usr/lib/systemd/system/ssh.service

change the following line in [Unit]

After=network.target auditd.service

to

After=network-online.target auditd.service

This will make sshd start after NetworkManager brings interfaces up, so it can bind to a specific IP rather than 0.0.0.0

Worked for me

First, this proved to be one of few problems of my carrier, for which I couldn't find any solution on Google/Stack Exchange etc!!

In the end, after spending more than 2 to 3 'FULL' days on this problem and reading tens of web pages, I finally happen to solve it by accident.

When the instance was showing its display thru serial ports, I happen no note one error which showed that it was trying to mount a hard disk, which was no longer available. And on further looking, I found that because of this 'unfindable' disk, the nginx service wasn't starting (I don't know the reasons behind this). And because of this, later I found, the ssh daemon service wasn't being started (I don't know why ssh(d) service was able to start manually when I commanded it thus?!!

So, solution is, edited the file /etc/fstab and removed the auto-mounting line from it. It caused Nginx to load properly, which caused 'sshd' to start/load properly!!

And to think!!, no solution on tens of forums, happen to mention this.

In my case I've solved it with stop, disable, enable and restart service ssh.

  1. sudo systemctl stop ssh
  2. sudo systemctl disable ssh
  3. sudo systemctl enable ssh
  4. sudo systemctl restart ssh

On ubuntu 18.04.06 LTS

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like