molly-guard installs a shell script that overrides the existing shutdown/reboot/halt/poweroff commands and first runs a set of scripts, which all have to exit successfully, before molly-guard invokes the real command.
One of the scripts checks for existing SSH sessions. If any of the four commands are called interactively over an SSH session, the shell script prompts you to enter the name of the host you wish to shut down. This should adequately prevent you from accidental shutdowns and reboots.
This shell script passes through the commands to the respective binaries in /sbin and should thus not get in the way if called non-interactively, or locally.
The tool is basically a replacement for halt, reboot and shutdown to prevent such accidents.
Install molly-guard in ubuntu
sudo apt-get install molly-guard
or click on the following link
Now that it's installed, try it out (on a non production box). Here you can see it save me from rebooting the box Ubuntu-test
Ubuntu-test:~$ sudo reboot
W: molly-guard: SSH session detected!
Please type in hostname of the machine to reboot: ruchi
Good thing I asked; I won't reboot Ubuntu-test ...
W: aborting reboot due to 30-query-hostname exiting with code 1.
By default you're only protected on sessions that look like SSH sessions (have $SSH_CONNECTION set). If, like us, you use alot of virtual machines and RILOE cards, edit /etc/molly-guard/rc and uncomment ALWAYS_QUERY_HOSTNAME=true. Now you should be prompted for any interactive session.
Incoming search terms:
- molly guard
- molly-guard linux
- W: molly-guard: SSH session detected!
- aborting reboot due to 30-query-hostname exiting with code 1
- moly guard
- reboot guard