Ubuntu 20.04 - 解决 Failed to enable unit: Unit file sshd.service does not exist.

Ubuntu 版本信息:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal

起因

事情是这样的,原本 SSH 服务是可用的:

$ sudo systemctl status sshd
[sudo] password for mk: 
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-02-19 19:19:56 CST; 1min 23s ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 840 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
   Main PID: 856 (sshd)
      Tasks: 1 (limit: 4588)
     Memory: 2.4M
     CGroup: /system.slice/ssh.service
             └─856 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups

219 19:19:56 mk-virtual-machine systemd[1]: Starting OpenBSD Secure Shell server...
219 19:19:56 mk-virtual-machine sshd[856]: Server listening on 0.0.0.0 port 22.
219 19:19:56 mk-virtual-machine sshd[856]: Server listening on :: port 22.
219 19:19:56 mk-virtual-machine systemd[1]: Started OpenBSD Secure Shell server.

嗯,我手痒,执行了 sudo systemctl disable sshd 命令:

$ sudo systemctl disable sshd
Removed /etc/systemd/system/sshd.service.
Removed /etc/systemd/system/multi-user.target.wants/ssh.service.

当我再次使用 sudo systemctl status sshd 命令,就出现了:

$ sudo systemctl status sshd
Unit sshd.service could not be found.

使用 sudo systemctl enable sshdsudo systemctl restart sshd 命令,也出现类似情况:

$ sudo systemctl enable sshd
Failed to enable unit: Unit file sshd.service does not exist.
$ sudo systemctl restart sshd
Failed to restart sshd.service: Unit sshd.service not found.

解决方法

后来是卸载、重装 SSH 才得以解决:

$ sudo apt-get remove --purge openssh-server
$ sudo apt-get update
$ sudo apt-get install openssh-server

参考

SSH Server cannot be found - Even though installed

  • 8
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
根据提供的引用信息,出现错误消息"Failed to restart httpd.service: Unit httpd.service not found"可能是由于没有安装或未正确配置httpd服务导致的。参考中的解决方法是通过卸载和重装openssh-server来解决类似问题,但与httpd服务相关的解决方法可能会有所不同。 为了解决该问题,您可以尝试以下步骤: 1. 确认httpd服务是否已正确安装。您可以使用命令"sudo apt-get install apache2"来安装httpd服务。如果已安装,请跳过此步骤。 2. 如果已安装httpd服务,请使用命令"sudo systemctl restart apache2"来重启httpd服务。 3. 如果重启httpd服务失败并出现"Unit httpd.service not found"的错误消息,可能是因为服务配置文件不存在或被重命名。您可以检查"/etc/systemd/system/"目录下是否存在"httpd.service"文件。如果不存在,请检查是否使用了正确的服务名称。 4. 如果服务配置文件确实不存在,请尝试重新安装httpd服务。您可以使用命令"sudo apt-get purge apache2"来卸载httpd服务,然后使用命令"sudo apt-get install apache2"来重新安装httpd服务。 5. 完成安装后,请使用命令"sudo systemctl restart apache2"再次尝试重启httpd服务。 请注意,以上步骤是基于Ubuntu操作系统的假设,并且假设您希望使用httpd服务。如果您使用的是其他操作系统或希望使用其他Web服务器,可能需要采取不同的步骤。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Ubuntu 20.04 - 解决 Failed to enable unit: Unit file sshd.service does not exist.](https://blog.csdn.net/qq_29761395/article/details/123022985)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值