Not shutting down the wrong machine
Posted: Tue Jul 08, 2025 8:57 am
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:
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:
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:~#
Two more points:
- 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.
- 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.