Page 1 of 1

Not shutting down the wrong machine

Posted: Tue Jul 08, 2025 8:57 am
by b3ta
I expect quite a few of the users on this forum have more than one box, and for those of us who log in via SSH to do things somewhere else, a momentary lapse of concentration can be quite problematic if you believe you're shutting down one machine while you're actually on another.

I've been using the "molly-guard" package for absolute ages and it's saved me a few times. It works with SSH (IIRC, also with Mosh), as this example demonstrates:

Code: Select all

root@server:~# shutdown -hP now
W: molly-guard: SSH session detected!
Please type in hostname of the machine to shutdown: Aargh!
Good thing I asked; I won't shutdown server ...
W: aborting shutdown due to 30-query-hostname exiting with code 1.
root@server:~# 
The story behind it is fascinating. Read one of those claiming to be the truth here: http://catb.org/jargon/html/M/molly-guard.html

Two more points:
  1. Its man page notes some important caveats. While they don't mention it by name, tmux is one of them. I didn't RTFM and discovered this last week. While I did intend to reboot the machine, it was a surprise, and led me to write this tip.
  2. The man page doesn't mention it, but the file "/etc/molly-guard/rc" has an "ALWAYS_QUERY_HOSTNAME" setting, which I feel should be mandatory on any important machine.

Re: Not shutting down the wrong machine

Posted: Fri Jul 11, 2025 9:11 am
by CharlesV
This is excellent! I tried this a few days back and it worked perfectly for me!

Re: Not shutting down the wrong machine

Posted: Fri Jul 11, 2025 1:29 pm
by DukeComposed
b3ta wrote: Tue Jul 08, 2025 8:57 am I've been using the "molly-guard" package for absolute ages and it's saved me a few times. It works with SSH
Fun fact: Molly-guards are named molly-guards because a programmer's young daughter hit the big red kill switch on an IBM 4341 at the University of Illinois twice in one day. They had to improvise a little plastic shield to keep her, or anyone else, from unintentionally pushing the kill switch. In retrospect, I have to wonder why IBM didn't think of this before they started selling machines with big red kill switches. You can probably guess the daughter's name.