Question: I keep typing shutdown on the wrong server. How do I protect against this?
Try: sudo tee /etc/molly-guard/run.d/50-prod-check <<'EOF' > /dev/null #!/bin/bash if [[ -f /etc/is_production ]]; then read -r -p "PRODUCTION server! Type the hostname to confirm shutdown: " input [[ "$input" == "$(hostname)" ]] || exit 1 fi EOF
Info:molly-guard intercepts shutdown, reboot, and halt commands over active SSH connections and demands explicit hostname confirmation to prevent catastrophic human errors.
Examples:
$ sudo apt install molly-guard # Install the safety utility
$ echo 'ALWAYS_QUERY_HOSTNAME=1' | sudo tee -a /etc/molly-guard/rc # Force hostname prompts globally
Note: By default, molly-guard only triggers on remote SSH sessions, leaving physical console access unaffected. A must-have safeguard for production server fleets.
LinuxTeck.com
linuxteck:~$ sudo tee /etc/molly-guard/run.d/50-prod-check <<'EOF' > /dev/null
#!/bin/bash
if [[ -f /etc/is_production ]]; then
read -r -p "PRODUCTION server! Type the hostname to confirm shutdown: " input
[[ "$input" == "$(hostname)" ]] || exit 1
fi
EOF
linuxteck@prod-db-01:~$ sudo chmod +x /etc/molly-guard/run.d/50-prod-check
linuxteck@prod-db-01:~$ sudo touch /etc/is_production
linuxteck@prod-db-01:~$ sudo shutdown now
W: molly-guard: SSH session detected!
PRODUCTION server! Type the hostname to confirm shutdown: prod-db-01
Shutdown proceeding...
linuxteck@prod-db-01:~$ sudo shutdown now
W: molly-guard: SSH session detected!
PRODUCTION server! Type the hostname to confirm shutdown: wrong
Shutdown aborted.
linuxteck@prod-db-01:~$
John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.
Leave a Reply