problem with openssh-server on ubunu 20.04

Something seems to have gone wrong with openssh-server on my machine. I'm on Ubuntu 20.04. I noticed this trying to install another package that depends on openssh-server.

When I tried to re-install it says it is configuring a "partially installed package" so I must have missed something happening with this package on a previous upgrade I think.

andy@andy-UX303UA:~$ sudo aptitude install openssh-server
The following partially installed packages will be configured:
  openssh-server 
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 20 not upgraded.
Need to get 0 B of archives. After unpacking 0 B will be used.
Setting up openssh-server (1:8.2p1-4ubuntu0.2) ...
rescue-ssh.target 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; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Wed 2021-05-26 10:25:29 BST; 9ms ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 45270 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=1/FAILURE)

May 26 10:25:29 andy-UX303UA systemd[1]: Failed to start OpenBSD Secure Shell server.
dpkg: error processing package openssh-server (--configure):
 installed openssh-server package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 openssh-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
Setting up openssh-server (1:8.2p1-4ubuntu0.2) ...
rescue-ssh.target 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; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Wed 2021-05-26 10:25:34 BST; 9ms ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 45546 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=1/FAILURE)
dpkg: error processing package openssh-server (--configure):
 installed openssh-server package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 openssh-server
                                         
andy@andy-UX303UA:~$ apt-cache policy openssh-server
openssh-server:
  Installed: 1:8.2p1-4ubuntu0.2
  Candidate: 1:8.2p1-4ubuntu0.2
  Version table:
 *** 1:8.2p1-4ubuntu0.2 500
        500 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
        100 /var/lib/dpkg/status
     1:8.2p1-4 500
        500 http://gb.archive.ubuntu.com/ubuntu focal/main amd64 Packages

The suggested places to look for more details don't seem particularly informative to me.

andy@andy-UX303UA:~$ systemctl status ssh.service
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2021-05-26 10:27:27 BST; 7min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 45953 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=1/FAILURE)

May 26 10:27:26 andy-UX303UA systemd[1]: Failed to start OpenBSD Secure Shell server.
May 26 10:27:27 andy-UX303UA systemd[1]: ssh.service: Scheduled restart job, restart counter is at 5.
May 26 10:27:27 andy-UX303UA systemd[1]: Stopped OpenBSD Secure Shell server.
May 26 10:27:27 andy-UX303UA systemd[1]: ssh.service: Start request repeated too quickly.
May 26 10:27:27 andy-UX303UA systemd[1]: ssh.service: Failed with result 'exit-code'.
May 26 10:27:27 andy-UX303UA systemd[1]: Failed to start OpenBSD Secure Shell server.
andy@andy-UX303UA:~$ journalctl -xe
-- Support: http://www.ubuntu.com/support
-- 
-- A start job for unit ssh.service has finished with a failure.
-- 
-- The job identifier is 17319 and the job result is failed.
May 26 10:36:35 andy-UX303UA update-notifier.desktop[47663]: /var/lib/dpkg/lock:
May 26 10:36:35 andy-UX303UA systemd[1]: ssh.service: Scheduled restart job, restart counter is at 5.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Automatic restarting of the unit ssh.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
May 26 10:36:35 andy-UX303UA systemd[1]: Stopped OpenBSD Secure Shell server.
-- Subject: A stop job for unit ssh.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- A stop job for unit ssh.service has finished.
-- 
-- The job identifier is 17399 and the job result is done.
May 26 10:36:35 andy-UX303UA systemd[1]: ssh.service: Start request repeated too quickly.
May 26 10:36:35 andy-UX303UA systemd[1]: ssh.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- The unit ssh.service has entered the 'failed' state with result 'exit-code'.
May 26 10:36:35 andy-UX303UA systemd[1]: Failed to start OpenBSD Secure Shell server.
-- Subject: A start job for unit ssh.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- A start job for unit ssh.service has finished with a failure.
-- 
-- The job identifier is 17399 and the job result is failed.
May 26 10:36:35 andy-UX303UA anacron[46167]: Job `cron.daily' terminated
May 26 10:36:35 andy-UX303UA anacron[46167]: Normal exit (1 job run)
May 26 10:36:35 andy-UX303UA systemd[1]: anacron.service: Succeeded.
-- Subject: Unit succeeded
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- The unit anacron.service has successfully entered the 'dead' state.
May 26 10:36:36 andy-UX303UA gnome-shell[1916]: JS ERROR: TypeError: windowActor is null
                                                _addWindowEffect@resource:///org/gnome/shell/ui/clos>
                                                vfunc_show@resource:///org/gnome/shell/ui/closeDialo>
May 26 10:36:37 andy-UX303UA sudo[46492]: pam_unix(sudo:session): session closed for user root
May 26 10:36:41 andy-UX303UA gnome-shell[1916]: JS ERROR: TypeError: windowActor is null
                                                _addWindowEffect@resource:///org/gnome/shell/ui/clos>
                                                vfunc_show@resource:///org/gnome/shell/ui/closeDialo>
May 26 10:36:46 andy-UX303UA gnome-shell[1916]: JS ERROR: TypeError: windowActor is null
                                                _addWindowEffect@resource:///org/gnome/shell/ui/clos>
                                                vfunc_show@resource:///org/gnome/shell/ui/closeDialo>
lines 2174-2227/2227 (END)

I got the same errors after running aptitude remove openssh-server and then trying to re-install it. Any ideas what to try next?

My ubuntu version:

andy@andy-UX303UA:~$ lsb_release -a
LSB Version:    core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:    20.04
Codename:   focal


Solution 1:

I don't know if aptitude remove purges the configuration, the man page is not that clear in my understanding. Instead of aptitude remove openssh-server you could try apt-get purge openssh-server and then install that package again.

If that doesn't help, you could try to get more information about this error:

dpkg: error processing package openssh-server (--configure):
installed openssh-server package post-installation script subprocess returned error exit status 1

It would be helpful to know why the post-installation script failed. After (re)installing the package, you could run dpkg-reconfigure openssh-server. I think it's worth a try, since executing this step separately might provide more information compared to having it wrapped by aptitude.