当我尝试运行 apt-get 或安装 Ubuntu 升级时,无法启动 OpenBSD Secure Shell 服务器错误

Joe*_*nar 9 server ssh apt

我在 Ubuntu 16.04 LTS 上。

我运行了 ssh 服务器并且它正常工作了好几个月,直到有一次导致它失败。

现在,我无法从 Canonical 进行常规的 Ubuntu 更新。我无法运行apt-get更新。例如

$ sudo apt-get upgrade python3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3 is already the newest version (3.5.1-3).
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  containerd libllvm5.0 libpaps0 paps python3-rlp runc swarm
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up openssh-server (1:7.2p2-4ubuntu2.6) ...
insserv: warning: script 'S02ssh-start.sh' missing LSB tags and overrides
insserv: warning: script 'ssh-start.sh' missing LSB tags and overrides
Job for ssh.service failed because the control process exited with error code. See "systemctl status ssh.service" and "journalctl -xe" for details.
invoke-rc.d: initscript ssh, action "restart" failed.
? ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-01-28 14:10:23 EST; 6ms ago
  Process: 79047 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=255)
  Process: 79038 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Main PID: 79047 (code=exited, status=255)

Jan 28 14:10:23 joeslinux systemd[1]: Starting OpenBSD Secure Shell server...
Jan 28 14:10:23 joeslinux systemd[1]: ssh.service: Main process exited, code=exited, status=255/n/a
Jan 28 14:10:23 joeslinux systemd[1]: Failed to start OpenBSD Secure Shell server.
Jan 28 14:10:23 joeslinux systemd[1]: ssh.service: Unit entered failed state.
Jan 28 14:10:23 joeslinux systemd[1]: ssh.service: Failed with result 'exit-code'.
dpkg: error processing package openssh-server (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 openssh-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)

当我检查 ssh 服务器的状态时,

sudo service ssh status

? ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-01-28 14:10:23 EST; 2min 37s ago
  Process: 79047 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=255)
  Process: 79038 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Main PID: 79047 (code=exited, status=255)

Jan 28 14:10:23 joeslinux systemd[1]: Starting OpenBSD Secure Shell server...
Jan 28 14:10:23 joeslinux systemd[1]: ssh.service: Main process exited, code=exited, status=255/n/a
Jan 28 14:10:23 joeslinux systemd[1]: Failed to start OpenBSD Secure Shell server.
Jan 28 14:10:23 joeslinux systemd[1]: ssh.service: Unit entered failed state.
Jan 28 14:10:23 joeslinux systemd[1]: ssh.service: Failed with result 'exit-code'.
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助。

-- 编辑 1/28/19 --

我不知道这是否有帮助,但我有 /etc/init.d以下 2 个脚本......

ssh.sh
Run Code Online (Sandbox Code Playgroud)

这似乎是 Ubuntu 提供的 shell 脚本

ssh-start.sh
Run Code Online (Sandbox Code Playgroud)

其中包含

sudo service ssh start
Run Code Online (Sandbox Code Playgroud)

除此之外,我还有/etc/systemd/system/sshd.service,这是一个链接/lib/systemd/system/ssh.service

其中包含:

[Unit]
Description=OpenBSD Secure Shell server
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run

[Service]
EnvironmentFile=-/etc/default/ssh
ExecStartPre=/usr/sbin/sshd -t
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecReload=/usr/sbin/sshd -t
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify

[Install]
WantedBy=multi-user.target
Alias=sshd.service
Run Code Online (Sandbox Code Playgroud)

------------ 编辑 2019 年 2 月 18 日 ---------------

还是有问题。他们现在导致诸如 apt install 之类的事情失败。

谢谢,安德鲁邓恩,但我研究了那个答案和解决方案对我不起作用。

这是输出 journalctl -xe

joe@joeslinux:~$ journalctl -xe
Feb 18 21:42:34 joeslinux start-mining-monero-minergate-cpu.sh[1640]: [2019-02-18 21:42:34] Diff: 8782 CPU/GPU: 953.8 H/s
Feb 18 21:42:35 joeslinux start-mining-monero-minergate-cpu.sh[1640]: [2019-02-18 21:42:35] Diff: 8782 CPU/GPU: 964.0 H/s
Feb 18 21:42:36 joeslinux sudo[5685]: joe : TTY=pts/6 ; PWD=/home/joe ; USER=root ; COMMAND=/usr/sbin/service ssh restart
Feb 18 21:42:36 joeslinux sudo[5685]: pam_unix(sudo:session): session opened for user root by (uid=0)
Feb 18 21:42:36 joeslinux systemd[1]: Stopped OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit ssh.service has finished shutting down.
Feb 18 21:42:36 joeslinux systemd[1]: Starting OpenBSD Secure Shell server...
-- Subject: Unit ssh.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit ssh.service has begun starting up.
Feb 18 21:42:36 joeslinux sshd[5703]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use.
Feb 18 21:42:36 joeslinux sshd[5703]: error: Bind to port 22 on :: failed: Address already in use.
Feb 18 21:42:36 joeslinux sshd[5703]: fatal: Cannot bind any address.
Feb 18 21:42:36 joeslinux systemd[1]: ssh.service: Main process exited, code=exited, status=255/n/a
Feb 18 21:42:36 joeslinux systemd[1]: Failed to start OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit ssh.service has failed.
-- 
-- The result is failed.
Feb 18 21:42:36 joeslinux systemd[1]: ssh.service: Unit entered failed state.
Feb 18 21:42:36 joeslinux systemd[1]: ssh.service: Failed with result 'exit-code'.
Feb 18 21:42:36 joeslinux sudo[5685]: pam_unix(sudo:session): session closed for user root
Run Code Online (Sandbox Code Playgroud)

请注意:错误:绑定到端口 22... 行。

小智 14

此问题是由/etc/ssh/sshd_config文件的错误配置引起的。当服务尝试启动时,它无法识别此配置文件的每个字段。为了解决这个问题,您必须使用该工具

/usr/sbin/sshd -T
Run Code Online (Sandbox Code Playgroud)

如果 /etc/ssh/sshd_config 错误,这将显示错误的参数与行。

您必须更正此问题,然后重新启动服务:

/etc/init.d/sshd restart
Run Code Online (Sandbox Code Playgroud)


Ale*_*x W 6

如果在安装 Ubuntu Server 后立即发生这种情况,如果您没有空闲终端,请按Ctrl+或 F3,...F7 切换到另一个 TTY。F2它会要求您登录。然后,您应该能够运行sudo ssh-keygen -A然后重新启动,并且应该能够启动该服务。


小智 1

我遇到了同样的问题,我使用了此链接中的解决方法 2 SSH 服务器在重新启动后停止工作,原因是缺少 /var/run/sshd

我认为对我来说问题是我的内核太旧了,祝你好运


小智 1

我的 Ubuntu 18.04 解决这个问题的方法是删除以下行/etc/ssh/sshd_config

PermitRoot yes
Run Code Online (Sandbox Code Playgroud)

然后重新启动 sshd 服务

sudo systemctl restart sshd.service
Run Code Online (Sandbox Code Playgroud)