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.
- Tried installing and reinstalling the openssh-server.
- Ran this command:
sudo systemctl enable sshd.service - Ran this command:
systemctl enable sshd - Ran this command:
sudo update-rc.d sshd defaults - Ran this command:
systemctl enable ssh.socket - Checked that symbolic link of
/etc/rc*.d/S**sshare there - Commenting out the specific
ListenAddressdirective and addingListenAddress 0.0.0.0to let sshd listen on any address in the file : /etc/ssh/sshd_config. - Edited this line
# Required-Start: $remote_fs $syslogto this line# Required-Start: $remote_fs $syslog $networkin the file /etc/init.d./ssh (to stop sshd from starting before the network is ready). - Added this line:
sshd &to the (end of) file/etc/init.d/rc.local. - Edited this file:
/etc/rc.localand added this line:/etc/init.d/ssh start - Edited the
/etc/ssh/sshd_configfile and in it, change Port to 2222. Also set thePasswordAuthenticationtoyes. - 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.
23 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.
- sudo systemctl stop ssh
- sudo systemctl disable ssh
- sudo systemctl enable ssh
- sudo systemctl restart ssh
On ubuntu 18.04.06 LTS