发送关闭命令后,ssh 会话不会终止

Pro*_*ter 13 shutdown ssh debian systemd

每当我发送关闭或重新启动 Debian 服务器的命令时,我的 shell 都会挂起并且没有响应(无法输入任何命令)。

在此处输入图片说明

在 Ubuntu 中执行相同的操作会导致会话正常关闭,因此我没有一个捆绑的终端挂在那里。是否有我需要安装的软件包或要进行的配置更改,以便我可以在 Debian 上获得相同的行为?

miv*_*ivk 11

这对我有用:

apt-get install libpam-systemd dbus
Run Code Online (Sandbox Code Playgroud)

还要确保UsePAM yes您的 ssh 配置中有。

grep -i UsePAM /etc/ssh/sshd_config
Run Code Online (Sandbox Code Playgroud)

不幸的是,您需要重新启动才能使解决方案生效...

关于serverfault 的详细解释。


neu*_*ron 7

看起来这是systemd当前在错误 #751636下跟踪的问题。

当主机关闭或重新启动时,systemd可能会在终止 ssh 会话之前关闭网络。

提供了几种解决方案,但没有具体的解决方案:

  1. 使用acpid/acpi-support-base来处理电源事件及以下添加到/etc/acpi/powerbtn-acpi-support.sh

    else
    -       # 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
    +
    fi
    
    Run Code Online (Sandbox Code Playgroud)

    然后在你的~/.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'
    
    Run Code Online (Sandbox Code Playgroud)
  2. /etc/systemd/system/ssh-user-sessions.service在其中创建以下内容:

    [Unit]
    Description=Shutdown all ssh sessions before network
    After=network.target
    
    [Service]
    TimeoutStartSec=0
    Type=oneshot
    RemainAfterExit=yes
    ExecStart=/bin/true
    ExecStop=/usr/bin/killall sshd
    
    Run Code Online (Sandbox Code Playgroud)