MOLLY-GUARD(8)
π MOLLY-GUARD π
okay bestie, pull up a chair, because molly-guard (that's the manual page molly-guard(8), section 8, admin-girlie territory) is about to save you from the single most embarrassing thing you can do on a server: yeeting a machine you were not supposed to yeet. π«Ά
β¨ NAME β¨
molly-guard β guard against accidental shutdowns/reboots
like, it literally exists so you don't shut down the wrong box at 3am. iconic behavior tbh.
πΈ SYNOPSIS πΈ
shutdown [-hV] [--molly-guard-do-nothing] [-- script_options]
halt [-hV] [--molly-guard-do-nothing] [-- script_options]
reboot [-hV] [--molly-guard-do-nothing] [-- script_options]
poweroff [-hV] [--molly-guard-do-nothing] [-- script_options]
coldreboot [-hV] [--molly-guard-do-nothing] [-- script_options]
pm-hibernate [-hV] [--molly-guard-do-nothing] [-- script_options]
pm-suspend [-hV] [--molly-guard-do-nothing] [-- script_options]
pm-suspend-hybrid [-hV] [--molly-guard-do-nothing] [-- script_options]
π DESCRIPTION π
so here's the vibe: molly-guard tries to stop you from accidentally shutting down or rebooting machines. no cap. it does this by injecting a couple of checks before the existing commands: coldreboot, halt, reboot, shutdown, poweroff, pm-hibernate, pm-suspend and pm-suspend-hybrid.
the way it works is lowkey genius: before molly-guard invokes the real command, all scripts in /etc/molly-guard/run.d/ have to run and exit successfully. if even one of them doesn't? it aborts the command. periodt. and run-parts(1) is used to process the directory. π
molly-guard passes any script_options to the scripts, and also populates the environment with these variables:
MOLLYGUARD_CMDβ the actual command invoked by the user.MOLLYGUARD_DO_NOTHINGβ set to1if this is a demo-run.MOLLYGUARD_SETTINGSβ the path to a shell script snippet which scripts can source to obtain settings.
also, molly-guard prints the contents of /etc/molly-guard/messages.d/COMMAND or /etc/molly-guard/messages.d/default to the console, if either exists. this is due to /etc/molly-guard/run.d/10-print-message. cute, right? πΈ
π¦ GUARDING SSH SESSIONS π¦
molly-guard was primarily designed to shield SSH connections. this functionality (which should arguably be provided by the openssh-server package) is implemented in /etc/molly-guard/run.d/30-query-hostname.
this script first tests whether the command is being executed from a tty which has been created by sshd. it also checks whether the variable SSH_CONNECTION is defined. if any of these tests are successful, test script queries the user for the machine's hostname, which should be sufficient to prevent the user from doing something by accident. it's giving "type the hostname to confirm bestie". π
you can pass the --pretend-ssh script option to molly-guard to pretend that those tests succeeds. alternatively, setting ALWAYS_QUERY_HOSTNAME in /etc/molly-guard/rc causes the script to always query.
π the following situations are still UNGUARDED. if you can think of ways to protect against those, please let me know! - runningsudowithinscreenorscreenwithinsudo;sudoeats theSSH_CONNECTIONvariable, andscreencreates a new pty. - executing those command in a remote terminal window, that is a XTerm started on a remote machine but displaying on the local X server.
you have been warned. π you can use the --molly-guard-do-nothing switch to prevent anything from happening, e.g. halt --molly-guard-do-nothing.
π OPTIONS π
--molly-guard-do-nothingβ causemolly-guardto print the command which would be executed, after processing all scripts, instead of executing it.-h,--helpβ display usage information.-V,--versionβ display version information.
π SEE ALSO π
shutdown(8), halt(1), reboot(8), poweroff(8). coldreboot(8). pm-hibernate(8). pm-suspend(8). pm-suspend-hybrid(8).
π LEGALESE π
molly-guard is copyright by martin f. krafft. Andrew Ruthven came up with the idea of using the scripts directory and submitted a patch, which I modified a bit.
this manual page was written by martin f. krafft <madduck@madduck.net>.
permission is granted to copy, distribute and/or modify this document under the terms of the Artistic License 2.0.
π COPYRIGHT π
Copyright Β© 2008 martin f. krafft
and that's the whole page bestie, mwah π
the source line was literally just [FIXME: source] and the date on it was Apr 19, 2008 β so this vibe has been protecting servers since way before we were even online. slay. πβ¨π¦
π¦ where this page comes from
- debian trixie: molly-guard 0.8.5 Β· Artistic-2.0
- ubuntu noble: molly-guard 0.8.3 Β· Artistic-2.0
- ubuntu questing: molly-guard 0.8.5
- ubuntu resolute: molly-guard 0.8.5build1 Β· Artistic-2.0
- ubuntu stonking: molly-guard 0.8.6 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms