ssh无法启动 (code=exited, status=255)

服务器运行了一些脚本后,突然发现无法ssh了。

root@X61T:/home/liang# 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.

使用systemctl检查状态

Systemd是一个系统管理守护进程、工具和库的集合,用于取代System V初始进程。Systemd的功能是用于集中管理和配置类UNIX系统。在Linux生态系统中,Systemd被部署到了大多数的标准Linux发行版中,只有为数不多的几个发行版尚未部署。

常用的systemctl命令:

systemctl list-unit-files                               列出所有可用的单元 systemctl list-units                                     列出所有运行中单元 systemctl --failed                                        列出所有失败单元 systemctl status firewalld.service           检查某个单元或服务是否运行 systemctl list-unit-files --type=service    列出所有服务(启用和禁用) systemctl start httpd.service                    启动 systemctl restart httpd.service                 重启 systemctl stop httpd.service                     停止 systemctl reload httpd.service                 重载服务 systemctl status httpd.service                  检查状态

检查一下ssh.service的状态

root@X61T:/home/liang# systemctl status ssh.service

发现

Process: 3448 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=255)
Process: 3445 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
……
Jan 30 08:18:03 X61T systemd[1]: Starting OpenBSD Secure Shell server…
Jan 30 08:18:03 X61T systemd[1]: ssh.service: Main process exited, code=exited, status=255/n/a
Jan 30 08:18:03 X61T systemd[1]: Failed to start OpenBSD Secure Shell server.
Jan 30 08:18:03 X61T systemd[1]: ssh.service: Unit entered failed state.
Jan 30 08:18:03 X61T systemd[1]: ssh.service: Failed with result 'exit-code'.
使用journalctl访问内部的数据
root@X61T:/home/liang# journalctl -u ssh.service

Jan 30 08:18:03 X61T systemd[1]: Starting OpenBSD Secure Shell server… Jan 30 08:18:03 X61T systemd[1]: ssh.service: Main process exited, code=exited, Jan 30 08:18:03 X61T systemd[1]: Failed to start OpenBSD Secure Shell server. Jan 30 08:18:03 X61T systemd[1]: ssh.service: Unit entered failed state. Jan 30 08:18:03 X61T systemd[1]: ssh.service: Failed with result 'exit-code'.

systemd尝试提供一套集中化管理方案,从而统一打理全部内核及用户级进程的日志信息。这套系统能够收集并管理日志内容,而这也就是journal。journal的实现归功于journald守护进程,其负责处理由内核、initrd以及服务等产生的信息。

对比一下 init.d 和 systemd :