Error While Binding Sshd to Port 2222 During Update on Debian 10 "Buster"

Got here following error output while updating:

Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)
Setting up openssh-server (1:7.9p1-10+deb10u1) ... is a disabled or a static unit, not starting it.
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; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-10-14 12:57:57 -03; 7ms ago

Docs: man:sshd(8)
Process: 22241 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Process: 22242 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=255/EXCEPTION)
Main PID: 22242 (code=exited, status=255/EXCEPTION)

Oct 14 12:57:57 wdbuster systemd[1]: Starting OpenBSD Secure Shell server...
Oct 14 12:57:57 wdbuster sshd[22242]: error: Bind to port 2222 on failed: Address already in use.
dpkg: error processing package openssh-server (--configure):
installed openssh-server package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of ssh:
ssh depends on openssh-server (>= 1:7.9p1-10+deb10u1); however:
Package openssh-server is not configured yet.

dpkg: error processing package ssh (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
Press Return to continue, 'q' followed by Return to quit.

Then, $ sudo dpkg --audit returned following output:

The following packages have been unpacked but not yet configured.
They must be configured using dpkg --configure or the configure
menu option in dselect for them to work:
ssh secure shell client and server (metapackage)

The following packages are only half configured, probably due to problems
configuring them the first time. The configuration should be retried using
dpkg --configure <package> or the configure menu option in dselect:
openssh-server secure shell (SSH) server, for secure access from remote

Considering too that port 22 is changed to 2222, on /etc/ssh/sshd_config.

Any ideas?

Asked By: Vascon63


One may proceed as follows:

$ sudo systemctl disable sshd
$ sudo systemctl daemon-reload
$ sudo dpkg --configure openssh-server

Then, finally

$ systemctl enable sshd

Answered By: Ferrari21
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.