[SOLVED] Failed to restart sshd.service: Unit sshd.service not found Ubuntu VirtualBox VM.

This guide explains the steps to fix the error:- Failed to restart sshd.service: Unit sshd.service not found

FAQ: How to fix: Failed to restart sshd.service: Unit sshd.service not found

Solution: reinstall the openssh server to fix it

Scenario: – SSH not working or sshd restart not working

dev@codetryout:~$ sudo systemctl restart sshd.service
Failed to restart sshd.service: Unit sshd.service not found.

This happens because the current OpenSSH configurations or the OpenSSH binary itself is misconfigured or corrupted. To fix this, I tried to purge the current OpenSSH installation and installed it again

Step #1 Removing the OpenSSH server completely

First, uninstall your OpenSSH server by using the apt purge option

sudo apt purge openssh-server

Step #2 Re-install Open SSH server

Now, re-install the ssh again.

sudo apt install openssh-server

References:

I have followed all the steps in the Ubuntu documentation repeatedly, but it didn’t fix the problem. Then follow this StackOverflow guide.