E: openssh-server: subprocess installed post-removal script returned error exit status 1

Asked by laeg

Binary package hint: openssh-server

I received the following two errors when trying to reinstall ssh and openssh-server after removing [I].ssh[/I] from my ~, [I]sudo rm -rf /etc/ssh[/I] and removing both with synaptic:

E: openssh-server: subprocess installed post-installation script returned error exit status 2
E: ssh: dependency problems - leaving unconfigured

Should this concern me and if so how do I remedy it?

Release: 9.10

laeg@skyrocket:~$ apt-cache policy ssh
ssh:
  Installed: 1:5.1p1-6ubuntu2
  Candidate: 1:5.1p1-6ubuntu2
  Version table:
 *** 1:5.1p1-6ubuntu2 0
        500 http://ie.archive.ubuntu.com karmic/main Packages
        100 /var/lib/dpkg/status
laeg@skyrocket:~$ apt-cache policy openssh-server
openssh-server:
  Installed: 1:5.1p1-6ubuntu2
  Candidate: 1:5.1p1-6ubuntu2
  Version table:
 *** 1:5.1p1-6ubuntu2 0
        500 http://ie.archive.ubuntu.com karmic/main Packages
        100 /var/lib/dpkg/status

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu openssh Edit question
Assignee:
No assignee Edit question
Solved by:
laeg
Solved:
Last query:
Last reply:
Revision history for this message
Neil Perry (nperry) said :
#1

Thank you for taking the time to report this issue and helping to make Ubuntu better. Examining the information you have given us, this does not appear to be a bug report so we are closing it and converting it to a question in the support tracker. We appreciate the difficulties you are facing, but it would make more sense to raise problems you are having in the support tracker at https://answers.launchpad.net/ubuntu if you are uncertain if they are bugs. For help on reporting bugs, see https://help.ubuntu.com/community/ReportingBugs .

Revision history for this message
Neil Perry (nperry) said :
#2

In above openssh-server package is not getting removed because of script error. Mostly these are shell script written using /bin/sh. These scripts called with -e option which means if not interactive, exit immediately if any untested command fails. The exit status of a command is considered to be explicitly tested if the command is used to control an if, elif, while, or until; or if the command is the left hand operand of an && or || operator. In short shell scripts will abort with an error if something fails. To fix this problem visit /var/lib/dpkg/info directory

$ cd /var/lib/dpkg/info

Now find out files in following format:
$ ls openssh-server.*

Should output something like openssh-server.postinst openssh-server.preinst openssh-server.postrm openssh-server.prerm

Now open each file and find out line that read as follows:

#/bin/sh -e

Replace with
#/bin/sh

Save and close all the files. Now run apt-get / dpkg command again to remove package:
# apt-get --purge remove openssh-server

Revision history for this message
laeg (laeg-hax) said :
#3

Thanks.

Only 3/4 of the files found with ls openssh-server.* contained #/bin/sh -e. I change them to #/bin/sh, saved and did a # apt-get --purge remove openssh-server

laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get --purge remove openssh-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libgconfmm-2.6-1c2
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  openssh-server* ssh*
0 upgraded, 0 newly installed, 2 to remove and 3 not upgraded.
2 not fully installed or removed.
After this operation, 811kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 172201 files and directories currently installed.)
Removing ssh ...
Removing openssh-server ...
 * Stopping OpenBSD Secure Shell server sshd [ OK ]
Purging configuration files for openssh-server ...
rmdir: failed to remove `/etc/ssh': No such file or directory
/usr/sbin/deluser: The user `sshd' does not exist.
Processing triggers for man-db ...
Processing triggers for ufw ...
Processing triggers for ureadahead ...

I then tried to reinstall using synaptic's GUI which returned the error once again:

E: openssh-server: subprocess installed post-installation script returned error exit status 2
E: ssh: dependency problems - leaving unconfigured

Revision history for this message
Neil Perry (nperry) said :
#4

Ok back in /var/lib/dpkg/info

Open openssh-server.postrm in your text editor

you see something like this

" rm -f /etc/ssh/ssh_host_key /etc/ssh/ssh_host_key.pub
                rm -f /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key.pub
                rm -f /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_dsa_key.pub
                rm -f /etc/ssh/sshd_config
                rm -f /etc/ssh/sshd_not_to_be_run
                rmdir --ignore-fail-on-non-empty /etc/ssh

                update-rc.d ssh remove >/dev/null

                if which deluser >/dev/null 2>&1; then
                        deluser --quiet sshd > /dev/null || true
                fi
"

Remove this section, or comment it all out save that file and re-try!

Revision history for this message
laeg (laeg-hax) said :
#5

I removed all the -e again and commented out the section you outlined above before once again executing the purge command

laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get --purge remove openssh-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package openssh-server is not installed, so not removed
The following packages were automatically installed and are no longer required:
  libgconfmm-2.6-1c2
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

and then trying to reinstall openssh-server

laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get install openssh-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libgconfmm-2.6-1c2
Use 'apt-get autoremove' to remove them.
Suggested packages:
  rssh molly-guard openssh-blacklist openssh-blacklist-extra
The following NEW packages will be installed:
  openssh-server
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 0B/286kB of archives.
After this operation, 766kB of additional disk space will be used.
Preconfiguring packages ...
Selecting previously deselected package openssh-server.
(Reading database ... 172191 files and directories currently installed.)
Unpacking openssh-server (from .../openssh-server_1%3a5.1p1-6ubuntu2_i386.deb) ...
Processing triggers for ureadahead ...
Processing triggers for ufw ...
Processing triggers for man-db ...
Setting up openssh-server (1:5.1p1-6ubuntu2) ...
/var/lib/dpkg/info/openssh-server.postinst: 451: cannot create /etc/ssh/sshd_config: Directory nonexistent
dpkg: error processing openssh-server (--configure):
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
 openssh-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

and then trying to reinstall ssh:

laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get install ssh
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libgconfmm-2.6-1c2
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
  ssh
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
1 not fully installed or removed.
Need to get 0B/1,252B of archives.
After this operation, 45.1kB of additional disk space will be used.
Selecting previously deselected package ssh.
(Reading database ... 172200 files and directories currently installed.)
Unpacking ssh (from .../ssh_1%3a5.1p1-6ubuntu2_all.deb) ...
Setting up openssh-server (1:5.1p1-6ubuntu2) ...
/var/lib/dpkg/info/openssh-server.postinst: 451: cannot create /etc/ssh/sshd_config: Directory nonexistent
dpkg: error processing openssh-server (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of ssh:
 ssh depends on openssh-server; however:
  Package openssh-server is not configured yet.
dpkg: error processing ssh (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                          Errors were encountered while processing:
 openssh-server
 ssh
E: Sub-process /usr/bin/dpkg returned an error code (1)

Revision history for this message
Neil Perry (nperry) said :
#6

sudo mkdir /etc/ssh

Revision history for this message
laeg (laeg-hax) said :
#7

It does mention a missing dir /etc/ssh which I removed at the very start so:

laeg@skyrocket:/var/lib/dpkg/info$ sudo mkdir /etc/ssh
laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get install openssh-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
openssh-server is already the newest version.
openssh-server set to manually installed.
The following packages were automatically installed and are no longer required:
  libgconfmm-2.6-1c2
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
2 not fully installed or removed.
After this operation, 0B of additional disk space will be used.
Setting up openssh-server (1:5.1p1-6ubuntu2) ...
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
 * Restarting OpenBSD Secure Shell server sshd [ OK ]

Setting up ssh (1:5.1p1-6ubuntu2) ...

laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get install ssh
Reading package lists... Done
Building dependency tree
Reading state information... Done
ssh is already the newest version.
The following packages were automatically installed and are no longer required:
  libgconfmm-2.6-1c2
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

I then tried to remove and re-add it with synaptic again and got the same two errors :(

Revision history for this message
Neil Perry (nperry) said :
#8

That all seems ok to me!

Revision history for this message
laeg (laeg-hax) said :
#9

It's not okay, I tried to remove it with synaptic's GUI and got the same two errors...?

Revision history for this message
Neil Perry (nperry) said :
#10

It will do because its now overwritten /var/lib/dpkg/info/openssh-server.

sudo dpkg-reconfigure openssh-server

Is ssh working now?

Revision history for this message
laeg (laeg-hax) said :
#11

laeg@skyrocket:~$ sudo dpkg-reconfigure openssh-server
[sudo] password for laeg:
/usr/sbin/dpkg-reconfigure: openssh-server is broken or not fully installed
laeg@skyrocket:~$ sudo mkdir /etc/ssh
laeg@skyrocket:~$ cd /var/lib/dpkg/inf
bash: cd: /var/lib/dpkg/inf: No such file or directory
laeg@skyrocket:~$ cd /var/lib/dpkg/info
laeg@skyrocket:/var/lib/dpkg/info$ ls openssh-server.*
openssh-server.conffiles openssh-server.md5sums openssh-server.preinst
openssh-server.config openssh-server.postinst openssh-server.prerm
openssh-server.list openssh-server.postrm openssh-server.templates
laeg@skyrocket:/var/lib/dpkg/info$ nautilus /var/lib/dpkg/info

(nautilus:3269): Eel-CRITICAL **: eel_preferences_get_boolean: assertion `preferences_is_initialized ()' failed
laeg@skyrocket:/var/lib/dpkg/info$ sudo gedit openssh-server.postrpm
[sudo] password for laeg:
laeg@skyrocket:/var/lib/dpkg/info$ sudo gedit openssh-client.postrm
laeg@skyrocket:/var/lib/dpkg/info$ sudo gedit openssh-server.postrm
laeg@skyrocket:/var/lib/dpkg/info$ sudo gedit openssh-server.postinst
laeg@skyrocket:/var/lib/dpkg/info$ sudo gedit openssh-server.preinst
laeg@skyrocket:/var/lib/dpkg/info$ sudo gedit openssh-server.postrm
laeg@skyrocket:/var/lib/dpkg/info$ apt-get --purge remove openssh-server
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get --purge remove openssh-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  openssh-server* ssh*
0 upgraded, 0 newly installed, 2 to remove and 7 not upgraded.
2 not fully installed or removed.
After this operation, 811kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 172193 files and directories currently installed.)
Removing ssh ...
Removing openssh-server ...
 * Stopping OpenBSD Secure Shell server sshd [ OK ]
Purging configuration files for openssh-server ...
Processing triggers for man-db ...
Processing triggers for ufw ...
Processing triggers for ureadahead ...
ureadahead will be reprofiled on next reboot
laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get --purge remove ssh
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package ssh is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 7 not upgraded.
laeg@skyrocket:/var/lib/dpkg/info$ ssh laeg@87.192.92.168
ssh: connect to host my.internet.ip port 22: Connection refused
laeg@skyrocket:/var/lib/dpkg/info$ ps aux | grep ssh
laeg 1668 0.0 0.0 5808 612 ? Ss 11:04 0:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session gnome-session
laeg 3963 0.0 0.0 3040 800 pts/0 R+ 11:49 0:00 grep ssh
laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get install ssh
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get install ssh
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  openssh-server
Suggested packages:
  rssh molly-guard openssh-blacklist openssh-blacklist-extra
The following NEW packages will be installed:
  openssh-server ssh
0 upgraded, 2 newly installed, 0 to remove and 7 not upgraded.
Need to get 0B/287kB of archives.
After this operation, 811kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Preconfiguring packages ...
Selecting previously deselected package openssh-server.
(Reading database ... 172178 files and directories currently installed.)
Unpacking openssh-server (from .../openssh-server_1%3a5.1p1-6ubuntu2_i386.deb) ...
Selecting previously deselected package ssh.
Unpacking ssh (from .../ssh_1%3a5.1p1-6ubuntu2_all.deb) ...
Processing triggers for ureadahead ...
Processing triggers for ufw ...
Processing triggers for man-db ...
Setting up openssh-server (1:5.1p1-6ubuntu2) ...
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
 * Restarting OpenBSD Secure Shell server sshd [ OK ]

Setting up ssh (1:5.1p1-6ubuntu2) ...

laeg@skyrocket:/var/lib/dpkg/info$ sudo apt-get install openssh-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
openssh-server is already the newest version.
openssh-server set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 7 not upgraded.
laeg@skyrocket:/var/lib/dpkg/info$ ssh <email address hidden>
The authenticity of host 'my.internet.ip (my.internet.ip)' can't be established.
RSA key fingerprint is x:x:x:x:x:x etc etc
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'my.internet.ip' (RSA) to the list of known hosts.
<email address hidden>'s password:
Linux skyrocket 2.6.31-16-generic #53-Ubuntu SMP Tue Dec 8 04:01:29 UTC 2009 i686

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/

Last login: Tue Dec 8 17:15:16 2009 from remote.host.ip
laeg@skyrocket:~$ exit
logout
Connection to my.internet.ip closed.
laeg@skyrocket:/var/lib/dpkg/info$

Thanks, fixed :)

Revision history for this message
laeg (laeg-hax) said :
#12

Sorry for late reply!

Revision history for this message
Joe Baumgarten (joeba) said :
#13

I saw something similar in the 21.04 to 21.10 upgrade, i'll enter new issue 11/5/2021.
troubleshooting steps:
top - 23:36:07 up 1:19, 3 users, load average: 1.17, 1.14, 1.12
Tasks: 190 total, 2 running, 187 sleeping, 0 stopped, 1 zombie
%Cpu(s): 0.1 us, 25.6 sy, 0.0 ni, 74.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 1845.6 total, 97.4 free, 363.0 used, 1385.2 buff/cache
MiB Swap: 4095.9 total, 4047.4 free, 48.5 used. 1308.1 avail Mem

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  48256 root 20 0 2284 136 0 R 99.7 0.0 36:33.07 ucf
  48471 root 20 0 11908 3384 2804 R 1.3 0.2 0:00.13 top

 ps -ef | grep dpkg
root 17505 6341 0 22:53 pts/1 00:00:02 /usr/bin/dpkg --force-overwrite --status-fd 64 --configure --pending
root 17506 17505 0 22:53 pts/1 00:00:00 sh -c (test -x /usr/lib/needrestart/dpkg-status && /usr/lib/needrestart/dpkg-status || cat > /dev/null)
root 17507 17506 0 22:53 pts/1 00:00:00 sh -c (test -x /usr/lib/needrestart/dpkg-status && /usr/lib/needrestart/dpkg-status || cat > /dev/null)
root 17508 17507 0 22:53 pts/1 00:00:00 /bin/sh /usr/lib/needrestart/dpkg-status
root 48228 17505 0 22:59 pts/1 00:00:00 /usr/bin/perl -w /usr/share/debconf/frontend /var/lib/dpkg/info/openssh-server.postinst configure 1:8.4p1-5ubuntu1.1
root 48242 48228 0 22:59 pts/1 00:00:00 /bin/sh /var/lib/dpkg/info/openssh-server.postinst configure 1:8.4p1-5ubuntu1.1
root 48390 48381 0 23:25 pts/3 00:00:00 grep dpkg

 kill -1 48242
kill -9 48242
kill -9 48228
then it contineud the upgrade..