sudo service sshd restart出现Job for ssh.service failed……

出现的错误现象

1
2
3
4
service sshd restart

Job for ssh.service failed because the control process exited with error code.
See "systemctl status ssh.service" and "journalctl -xe" for details.

查找出现的错误原因

根据错误提示运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
systemctl status ssh.service
#提示为
  ● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: >
     Active: failed (Result: exit-code) since Sat 2020-12-12 10:50:04 CST; 1mi>
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 11657 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=255/EXC>

12月 12 10:50:04 li-virtual-machine systemd[1]: ssh.service: Scheduled restart>
12月 12 10:50:04 li-virtual-machine systemd[1]: Stopped OpenBSD Secure Shell s>
12月 12 10:50:04 li-virtual-machine systemd[1]: ssh.service: Start request rep>
12月 12 10:50:04 li-virtual-machine systemd[1]: ssh.service: Failed with resul>
12月 12 10:50:04 li-virtual-machine systemd[1]: Failed to start OpenBSD Secure>

如图所示
在这里插入图片描述
之后执行上图所示的ExecStartPre=/usr/sbin/sshd -t

1
2
3
4
5
6
7
8
/usr/sbin/sshd -T

提示/etc/ssh/sshd_config中61行 64 66 68行出现错误
/etc/ssh/sshd_config: line 61: Bad configuration option:     rootRootLogin
/etc/ssh/sshd_config: line 64: Bad configuration option: sudo
/etc/ssh/sshd_config: line 66: Bad configuration option: systemctl
/etc/ssh/sshd_config: line 68: Bad configuration option: m
/etc/ssh/sshd_config: terminating, 4 bad configuration options

在这里插入图片描述

解决办法

1
2
3
4
5
6
vi /etc/ssh/sshd_config
#61行rootRootLogin拼错
  PermitRootLogin
#64 66 68 行可以注释掉
#重启
service sshd restart