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.
- Ubuntu configure OpenSSH server – https://ubuntu.com/server/docs/service-openssh
- Ubuntu Unable to start the SSH service – https://askubuntu.com/questions/265982/unable-to-start-sshd
- CodeTryout guide on How to install OpenSSH server on Ubuntu VirtualBox VM