Introduction:
If your SSH service fails to start after a system reboot, one possible reason is the missing /var/run/sshd directory. This directory is required by the SSH daemon (sshd) to function correctly, but in some cases, it is not automatically created on boot. This can lead to SSH connection failures, preventing remote access to the server.

To resolve this issue, you need to ensure that the /var/run/sshd directory is created every time the system reboots. One way to achieve this, especially on older systems, is by modifying the /etc/rc.local file. The following steps outline how to configure /etc/rc.local to create the directory and restart the SSH service automatically.

Prerequisite:
1. Server root credentials.
Step 1:
On systems that support /etc/rc.local, you can add commands to recreate the directory at boot.
Open /etc/rc.local for editing:

sudo nano /etc/rc.local

Step 2:
Add the following lines before exit 0

mkdir -p /var/run/sshd
chown root:root /var/run/sshd
chmod 755 /var/run/sshd
systemctl restart ssh

Save and exit.
Step 3:
Make sure /etc/rc.local is executable

sudo chmod +x /etc/rc.local

Verify the Fix
Reboot the server and check the SSH service status

sudo reboot

Step 4:
After rebooting, check

systemctl status ssh

Leave a Reply