Will "init 1" from a remote (via VPN) ssh session kill my ssh connection

Solution 1:

Yes, yes it will. Most services don't run in runlevel 1.

Solution 2:

It should be OK. Whilst the SSH listener daemon is stopped in runlevel 1 on most distros, existing connections should stay up, and networking shouldn't be affected. I wouldn't be doing it without having some sort of remote console connected, though -- you never know when a rogue solar flare is going to come along and drop your network connections for juuuuust long enough to kill your SSH session.

EDIT: Some testing indicates that, on Debian systems at least, /etc/rc1.d/S30killprocs will take down existing SSH connections (because it's killing off everything). I would be inclined to knobble that script temporarily and do it's job by hand (avoiding the SSH connections) if I were to try to do what you want to do. I'd still prefer to use a remote console, though.


Solution 3:

Sorry to bring up after such a long time. I needed answer to this same question. Current answers are wrong for my box. My findings are for Centos 5.11 based install.

  1. The reason ssh client gets disconnected is because init 1 does something like service network stop. What I observe is that and all network interfaces go down and get unconfigured. ip a and ifconfig -a confirm this.

  2. init 1 stops sshd listener process. It does not stop sshd child process that holds the session for the connected client. The ssh session eventually gets dropped due to TCP timeout because network goes down, ssh session does not get killed. If I bring the network back up service network start at the console quickly enough then my clients remain connected even though the box is at runlevel 1.

  3. Question mentions VPN. If the VPN server you are going though is on the box where you doing init 1 then yes, you normally will get disconnected because VPN server by default will NOT run at runlevel 1.

My work around to take system to runlevel 1 without losing ssh sessions, is to temporarily configure required services to continue running at run level 1. All based on Centos 5.11. YMMV. Disclaimer: I would not want to rely on this to work.

    # keep network interfaces up
    chkconfig --level 1 network on
    # if you are connecting though VPN e.g. OpenVPN running on same server
    chkconfig --level 1 openvpn on
    # While at it, might as well keep SSHD running, so you can reconnect
    chkconfig --level 1 sshd on

    init 1
    # look for messages that indicate that run level has been reached
    tail -F /var/log/messages
    # Aug 31 14:21:19 pabx-demo kernel: Kernel logging (proc) stopped.
    # Aug 31 14:21:19 pabx-demo kernel: Kernel log daemon terminating.
    # Aug 31 14:21:20 pabx-demo exiting on signal 15

That's it. This allows me to take box to init 1 remotely while remaining in control.

After you are done don't forget to undo the changes:

chkconfig --level 1 network off
chkconfig --level 1 openvpn off
chkconfig --level 1 sshd off

Tags:

Linux

Ssh

Vpn

Init