Ubuntu系统中执行sudo systemctl restart sshd报错Failed to restart sshd.service: Unit sshd.service not found的解决求助
Ubuntu系统中执行sudo systemctl restart sshd报错Failed to restart sshd.service: Unit sshd.service not found的解决求助
嘿,别慌,我来帮你捋捋这个问题~这在Ubuntu里其实是个挺常见的小坑,咱们一步步排查:
首先,Ubuntu的SSH服务名称大概率不是
sshd而是ssh
很多人会搞混这个,你先试试检查服务状态:sudo systemctl status ssh
如果能看到服务相关信息,直接用这个命令重启就行:sudo systemctl restart ssh如果服务还是找不到,先确认openssh-server有没有安装
有时候可能不小心没装服务端,先检查安装情况:dpkg -l | grep openssh-server
要是输出里没找到openssh-server,就先安装:sudo apt update && sudo apt install openssh-server
装完再用上面的ssh服务名重启试试。别忘了检查你修改的sshd_config有没有语法错误
你改了/etc/ssh/sshd_config文件,要是配置写错了,服务也可能启动失败(甚至找不到服务入口),先做语法检查:sshd -t
要是有错误提示,根据提示修正配置后再重启服务。实在不行,试试刷新systemd的服务缓存
偶尔systemd的服务缓存会出问题,执行这个命令重新加载:sudo systemctl daemon-reload
之后再尝试重启SSH服务。最后看日志找线索
要是以上方法都没用,看看系统日志里的详细错误信息,能帮你定位根因:journalctl -xe | grep ssh
备注:内容来源于stack exchange,提问作者Muftau Alatishe




