SSH Server stops working after reboot, caused by missing /var/run/sshd

I found this is a bug with the current version of systemd and old kernels that are used by some VPS privdes as it is in my case. This bug appears time to time, as we can see on Launchpad: Bug #45234, Bug #1811580; or on ServerFault: Why am I missing /var/run/sshd after every boot?

There are few workarounds of this issue, they all come together to alternative way to create /var/run/sshd before running the SSH server. Here are three possible solutions.


Workaround 1: Modify /usr/lib/tmpfiles.d/sshd.conf in the following way:

d /run/sshd 0755 root root

As it is mentioned in the question, /var/run is a symbolic link to /run, the final result is identical: /var/run/sshd is created. I do not know why, but this works.


Workaround 2: Use Cron job that will create /var/run/sshd and restart the SSH server, you can use the root's crontab for this purpose - execute sudo crontab -e and add the following entry:

@reboot mkdir -p -m0755 /var/run/sshd && systemctl restart ssh.service

Currently I'm using this solution, so it is also tested.


Workaround 3: Use /etc/rc.local to do the same as the above, as it is shown in this comment on bug report #45234.


Could you check whether your / (root filesystem) permissions are not changed? Have to be root:root like the two lines below:

drwxr-xr-x  25 root root      4096 дек 21 06:45 ..
drwxr-xr-x  25 root root      4096 дек 21 06:45 .

If the owner is another user (and not root) this will prevent creating all temporary files by systemd during system startup. You may check also with the command:

systemd-tmpfiles --create

If the root folder (/) has different permission, please change it with the following command:

chown root: /

Thanks everyone for helpful information. The problem with ssh-server on my Xenial Lubuntu was indeed related to ownership of '/' as suggested by Melebius & Stefan.
Manually creating /var/run/sshd and restarting ssh.service temporarily ssh-server temporarily. Editing the sshd.conf did not help in this system. Then following the last suggestion, I checked the root folder ownership with:

'ls -alF /' and sure enough, it had been accidentally changed to a local user/group. Issuing from the terminal: 'sudo chown root:root /' fixed my system, regardless of the edit to sshd.conf. So I restored that to its original state, i.e. d /var/run/sshd 0755 root root.