7

I am on Ubuntu 16.04 LTS.

I had ssh server running and it worked properly for many months, until one time when something cause it to fail.

Now, I can't do regular Ubuntu updates from Canonical. I can't run apt-get updates. E.g.

$ 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)

When I check the status of my ssh server,

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'.

Thank you for help.

-- edit 1/28/19 --

I don't know if this helps, but I have in /etc/init.d the following 2 scripts...

ssh.sh

which appears to be the Ubuntu provided shell script

and

ssh-start.sh

which contains

sudo service ssh start

in addition to all that, I also have /etc/systemd/system/sshd.service, which is a link to /lib/systemd/system/ssh.service

which contains:

[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

------------ edit February 18, 2019 -----------------------

Still having issues. They are now causing things like apt install to fail.

Thanks, Andrew Dunn, but I researched that answer and solution didn't work work me.

Here is output of 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

Note the: error: Bind to port 22... lines.

10

This issue is caused by a bad configuration of /etc/ssh/sshd_config file. When the service try to launch it does not recognize every fields of this configuration file. In order to solve this issue, you must use the tool

/usr/sbin/sshd -T

In case /etc/ssh/sshd_config was wrong, this would show wrong parameters with lines.

You must correct this issues and then restart the service:

/etc/init.d/sshd restart
2
1

I had the same problem, I used workaround 2 from this link SSH Server stops working after reboot, caused by missing /var/run/sshd

I think the issue for me is my kernal is too old, best of luck

1

If this happens right after installing Ubuntu Server, press Ctrl + F2 or F3,...F7 to switch to another TTY if you don't have a free terminal. It will ask you to login. Then, you should be able to run sudo ssh-keygen -A and then reboot and it should be able to start the service.

1
1

same problem with Ubuntu 16.04

● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: failed (Result: start-limit-hit) 
  Process: 3120 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=255)

6月 19 17:39:32 wx systemd[1]: Failed to start OpenBSD Secure Shell server.
6月 19 17:39:32 wx systemd[1]: ssh.service: Unit entered failed state.
6月 19 17:39:32 wx systemd[1]: ssh.service: Failed with result 'exit-code'.
6月 19 17:39:32 wx systemd[1]: ssh.service: Service hold-off time over, scheduling restart.
6月 19 17:39:32 wx systemd[1]: Stopped OpenBSD Secure Shell server.
6月 19 17:39:32 wx systemd[1]: ssh.service: Start request repeated too quickly.
6月 19 17:39:32 wx systemd[1]: Failed to start OpenBSD Secure Shell server.
6月 19 17:39:32 wx systemd[1]: ssh.service: Unit entered failed state.
6月 19 17:39:32 wx systemd[1]: ssh.service: Failed with result 'start-limit-hit'.

  • and just do next,
sudo mkdir /var/run/sshd &&  sudo service sshd start

Good Luck

0

What solved this problem for my Ubuntu 18.04 was to remove the following line in /etc/ssh/sshd_config

PermitRoot yes

and then restarting the sshd service with

sudo systemctl restart sshd.service
1
  • No, I do not have PermitRoot at all. – Joe Molnar Aug 25 '19 at 18:24
0

It happened to me when i wanted to disable SSH key login. First i set this:

sudo nano /etc/ssh/sshd_config

// set this in the file:
PasswordAuthentication yes (from no)

// save and call:
sudo service ssh restart

Then the error happened then I also added in the file above:

PubkeyAuthentication no

// then call
sudo service ssh restart

It seemed it fixed the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.