If you are acquainted with the command line on Linux or Unix systems, you’ve probably punched in the wrong command by mistake more times than you’d care to admit. It’s particularly frustrating when that mistake concerns shutting down the wrong machine, which can happen when you’re SSHing into multiple virtual machines. molly-guard is a tool that prevents accidental shutdowns or reboots.
molly-guard is an oldie but a goodie, though some new Linux users may not be aware of its existence. nixCraft writer Vivek Gite recently started using molly-guard after accidentally executing the
shutdown -h 0 command in the wrong terminal and ended up shutting down a database server instead of his home server. Those who have made similar mistakes know that it can be an infuriating experience.
molly-guard overrides commands associated with shutting down or restarting Linux/Unix machines including
poweroff. When you try to invoke those commands and an SSH session is detected, molly-guard will spring into action and check that you’re trying to shutdown/reboot the right machine by asking for confirmation of the host name.
Bear in mind, molly-guard’s powers are limited to SSH sessions so it won’t help you if you’re on the host machine’s console but it is quite useful for those who often have to SSH into multiple virtual machines.
To get molly-guard on your Linux/Unix machine, use the
apt-get install molly-guard command in the terminal.