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.