When I shut down or restart my server while logged in via SSH, the SSH connection hangs or freezes. The terminal becomes completely unresponsive, and it takes up to one minute for the SSH session to recognize that the connection has been lost.

This issue occurs on the new Debian 12 (openssh-server 1:9.2p1-2) but does not happen on the older Debian 10.

On Debian 10, when I restart the server, the SSH connection cleanly logs out immediately, displaying the following message:

Connection to debian10 closed by remote host.
Connection to debian10 closed.

When I connect with verbose options to both servers, and then restart them, I see some differences:

ssh session ends cleanly:

$ ssh -vvv -E /tmp/a debian10
debug3: send packet: type 1
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r0 i0/0 o0/0 e[write]/0 fd 6/7/8 sock -1 cc -1)

debug3: fd 1 is not O_NONBLOCK
Transferred: sent 4668, received 7428 bytes, in 34.8 seconds
Bytes per second: sent 134.3, received 213.7
debug1: Exit status -1

ssh session freezes:

$ ssh -vvv -E /tmp/b debian12
debug3: send packet: type 80
debug3: receive packet: type 82
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
Timeout, server debian12 not responding.

I have found similar questions, but all the answers suggest something to do with systemd. I am not using systemd, I am using sysvinit on both servers.

So, to sum up: The two servers behave differently using same ssh client, therefore I suspect something is different on the server side (presumably behavior of openssh-server)


Here is my restart sequence (runlevel 6):


note that ssh daemon is terminated before networking. But that should not have any effect anyway, because shutting down sshd normally does not affect existing ssh connections.


Here is the shutdown sequence, as I see it on the console:

[ ok  Sending processes configured via /etc/ini[....] Stopping: cron
[ ok ] Stopping: sshd
[ ok ] Asking all remaining processes to terminate...done.
[ ok ] All processes ended within 1 seconds...done.
[ ok ] Stopping: rsyslogd
[ ok ] Deconfiguring network interfaces...done.
[ ok ] Will now unmount temporary filesystems: /tmp
[ ok ] Will now unmount local filesystems: /var
[ ok ] Mounting root filesystem read-only...done.
[info] Will now halt.
[79896.954129] reboot: Power down
  • Are you positive that the shutdown/reboot procedure really completes regularly, not ending abruptly for some strange reason? can you see the expected messages from those rc6.d scripts on the console while rebooting? (note rc6 is for reboot only while typically rc0 is for shutdown/poweroff)
    – LL3
    Jun 20, 2023 at 13:42
  • @LL3 - I have updated my question with more details. See UPDATE2. Jun 21, 2023 at 1:53
  • 2
    Not the answer so I just write a comment: when it happens, you can write enter then ~ the . to free your terminal. Jun 22, 2023 at 6:56
  • Please update your post again to show the diff output of your /etc/ssh/sshd_config files. There may be a change in the default settings between the two servers. P.S. Good on you for eschewing systemd
    – Jim L.
    Jun 22, 2023 at 17:41
  • @Jim L. - the config files are identical Jun 23, 2023 at 4:38

2 Answers 2


root cause

With both systemd, which is standard, and with sysvinit, an orderly shutdown will kill daemons and deconfigure hardware in a certain order. In particular, we expect that while IP is still active the sshd that listens on 22, and the various sshd's with bash children that it spawned, should receive kill signals telling them to terminate. The IP stack should remain up for at least one second after those signals are sent. The timeouts you experience are consistent with client sending TCP traffic on an open connection to a server that is no longer responsive to those TCP packets.

On your debian12 server take a look at /etc/init.d/rc. When changing from multiuser runlevel 2 it kills daemons by running shutdown scripts with prefixes like K75, in order. Ensure that sshd is killed prior to ifconfig bringing your network interface down. Renaming a script to use a different two-digit sequence number will change the order of execution.

Notice that if scripts are racing one another, you can slow one down by inserting the occasional sleep statement.


Even if you have trouble sifting through the syslogs of that maze of twisty little init scripts, all alike, there are still some easy workarounds.

A simple shutdown -r +1 as root gives you 60 seconds to hit CTRL-D for a graceful ssh disconnect before the fireworks begin.

A command like (sleep 5 && reboot) & accomplishes that in less time. You might have to nohup it, or otherwise disown to detach the background process from your pty's job control. So it may be convenient to create a short script for the command.

Let us know what details needed to be changed on your system.

  • I don't think the sequence in which ssh daemon is shut down has any effect here. I have updated my question with more details. Jun 18, 2023 at 3:27

Check your /etc/ssh/sshd_config that UsePAM yes is configured Also ensure that libpam-systemd and dbus packages are installed

systemd-logind keeps records of active user sessions both local and remote (ssh) and assigns spawned processes to the users "slice". If this is configured properly when systemd is stopping it will SIGTERM everything inside your user slices which should include your ssh connection before network connections are disabled.

  • 1
    didn't you read my question? I said I am using sysvinit, not systemd Jun 22, 2023 at 3:54

You must log in to answer this question.

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