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

Asked by laeg on 2009-12-11

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:
2009-12-13
Last query:
2009-12-13
Last reply:
2009-12-11
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 .

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

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

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!

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)

Neil Perry (nperry) said : #6

sudo mkdir /etc/ssh

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 :(

Neil Perry (nperry) said : #8

That all seems ok to me!

laeg (laeg-hax) said : #9

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

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?

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

laeg (laeg-hax) said : #12

Sorry for late reply!