Preventing accidental Ctrl+Alt+Del reboots
I have been bitten a couple of times when I have multiple keyboards at a bench or I am using a KVM that makes a remote machine look just like my local one. There are several things I've done to stop this from happening:
- I set a custom PS1 prompt so I always see the server's name
- I change the definition of what happens when Ctrl+Alt+Del is pressed
- I put a front-end on the reboot command that reminds me of the server I am rebooting and prompts me to confirm, then pauses for three seconds so I have time to read the screen, say “whoops!”, and press ^C.
For an example of my custom prompt setting, see Make a colour BASH prompt.
To change the definition of what happens when Ctrl+Alt+Del is pressed just change the line in /etc/inittab to this:
ca:12345:ctrlaltdel:/usr/local/bin/noshutdown
… then create the file /usr/local/bin/noshutdown to say what you want, such as:
#!/bin/bash echo echo "This server cannot be shut down with Ctrl+Alt+Del." echo "Contact the server administrator (try root@`hostname -f`) for permission" echo "to shut down this server." echo
Finally, in my /etc/profile.d/bash-aliases.sh file I define an alias for the reboot command that gives me a nice, colourful prompt like so:
alias reboot='echo -en "\e[1;33;44m${HOSTNAME}\e[0;37m reboot? [\e[s___] <== must type yes\e[u"; read ans; if [ "$ans" = "yes" ]; then echo -en "Rebooting \e[1;33;44m${HOSTNAME}\e[0;37m in 3 seconds..."; sleep 3; shutdown -r now; fi'