Whenever I send the command to turn off or restart my Debian servers, my shell is left hanging and unresponsive (can't type any commands).

enter image description here

Performing the same action in Ubuntu results in the session gracefully closing so I don't have a tied-up terminal left hanging there. Is there a package I need to install or a configuration change to be made so that I can get this same behaviour on Debian?

  • Does the same behavior occur with sudo shutdown -h now (for poweroff), and/or sudo reboot (for restart)?
    – eyoung100
    Jul 18, 2015 at 20:01
  • yes, it occurs with those as well. Jul 18, 2015 at 20:15
  • 2
    NB you can kill one of these hung ssh sessions by typing <enter>, tilde, and period (~.).
    – Kenster
    Jul 19, 2015 at 0:27

2 Answers 2


This worked for me:

apt-get install libpam-systemd dbus

Also make sure that you have UsePAM yes in your ssh config.

grep -i UsePAM /etc/ssh/sshd_config

Unfortunately, you need to reboot for the solution to take effect...

Detailed explanations on serverfault.

  • I just had the same problem on ubuntu 16.04 for which the previous solution didn't work but this one did. Jun 8, 2016 at 15:12

Looks like that's a systemd issue currently tracked under bug #751636.

When the host is shut down or restarted, systemd might shut down the network before it kills the ssh session.

There are a couple of solutions provided but nothing concrete:

  1. Using acpid/acpi-support-base to handle the power events & add the following to the /etc/acpi/powerbtn-acpi-support.sh

    -       # Normal handling.
    -       /sbin/shutdown -h -P now "Power button pressed"
    +       if [ -x /bin/systemctl ] ; then
    +           echo "\nPower button pressed\nThe system is going down for system halt NOW!" |\
    +            /usr/bin/wall -n
    +           /bin/systemctl --force poweroff
    +       else
    +           # Normal handling.
    +           /sbin/shutdown -h -P now "Power button pressed"
    +       fi

    and then make aliases in your ~/.bashrc:

    alias reboot='echo "The system is going down for system reboot NOW!" |\
    /usr/bin/wall -n ; /bin/systemctl --force reboot'
    alias poweroff='echo "The system is going down for system halt NOW!" |\
    /usr/bin/wall -n ; /bin/systemctl --force poweroff'
  2. Creating /etc/systemd/system/ssh-user-sessions.service with the following in it:

    Description=Shutdown all ssh sessions before network
    ExecStop=/usr/bin/killall sshd
  • it's good to know its a bug thats known about. I tried the second solution, but it doesn't appear to work for me when sending the reboot command. I made sure to make it executable. Jul 19, 2015 at 8:00
  • 1
    Reload the systemd daemon: systemctl daemon-reload, also in-order to activate the systemd service immediately: systemctl start ssh-user-sessions.service and to enable the service at bootup systemctl enable ssh-user-sessions.service
    – neuron
    Jul 19, 2015 at 9:29
  • Running the first 2 commnds did the trick. Running the third command resulted in: The unit files have no [Install] section. They are not meant to be enabled using systemctl. but doesn't seem to be needed. Jul 19, 2015 at 9:34
  • Yeah, forgot to mention that Unit file may include an "[Install]" section, which carries installation information for the unit. This section is not interpreted by systemd during runtime. It is used exclusively by the enable and disable commands of the systemctl tool during installation of a unit.
    – neuron
    Jul 19, 2015 at 13:48
  • I added [Install] followed by WantedBy=multi-user.target to the file, which resulted in systemctl enable ssh-user-sessions.service not throwing an error and results in the service taking effect across reboots. Is there anything wrong with doing this? Sep 19, 2015 at 11:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .