无法启动 sshd 服务:无法启动 openssh.service:未找到单元

无法启动 sshd 服务:无法启动 openssh.service:未找到单元

在虚拟 rhel 7.4 上,当我尝试启动 sshd 服务时出现一个奇怪的错误。

无法启动 openssh.service:未找到单元

事实上,我在 sshd 上尝试任何操作时都会遇到同样的错误 - 启用、状态或停止

openssh 图片

我确实尝试重新启动该实例但似乎没有任何作用。

答案1

在运行 OpenSSH 服务器之前,您必须安装但您实际上并未安装它。要解决此问题,请安装 OpenSSH 服务器。

[root@localhost ~]# yum install openssh-server
Loaded plugins: product-id, search-disabled-repos, subscription-manager
Resolving Dependencies
--> Running transaction check
---> Package openssh-server.x86_64 0:7.4p1-16.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch      Version           Repository                  Size
================================================================================
Installing:
 openssh-server    x86_64    7.4p1-16.el7      rhel-7-server-beta-rpms    458 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 458 k
Installed size: 971 k
Is this ok [y/d/N]: y
Downloading packages:
openssh-server-7.4p1-16.el7.x86_64.rpm                     | 458 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : openssh-server-7.4p1-16.el7.x86_64                           1/1 
  Verifying  : openssh-server-7.4p1-16.el7.x86_64                           1/1 

Installed:
  openssh-server.x86_64 0:7.4p1-16.el7                                          

Complete!

该服务默认启用,但如果您需要管理它,systemd 单元名称是sshd

[root@localhost ~]# systemctl start sshd
[root@localhost ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-03-24 17:37:23 EDT; 41s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 1373 (sshd)
   CGroup: /system.slice/sshd.service
           └─1373 /usr/sbin/sshd -D

Mar 24 17:37:23 localhost.localdomain systemd[1]: Starting OpenSSH server dae...
Mar 24 17:37:23 localhost.localdomain sshd[1373]: Server listening on 0.0.0.0...
Mar 24 17:37:23 localhost.localdomain sshd[1373]: Server listening on :: port...
Mar 24 17:37:23 localhost.localdomain systemd[1]: Started OpenSSH server daemon.
Hint: Some lines were ellipsized, use -l to show in full.

答案2

如今,这项服务似乎被称为ssh,而不是sshd

sudo systemctl restart ssh

(这是在 Ubuntu 上通过 APT 安装的openssh-server软件包版本)1:8.2p1-4ubuntu0.5

相关内容