12 Mar 2007

Log and disabling Ctrl+Alt+Del

In a server rack, one console are usually shared by several different servers. One rack may contain servers belonging to different departments. One of those departments are usually doomed to have one trigger happy sysadmin. This sysadmin may reboot the wrong server accidentally using Ctrl+Alt+Del. Ever been exposed to one of those? Luckily, it easy to disable Ctrl+Alt+Del on Linux. On Linux, "/etc/inittab" defines what should be done when Ctrl+Alt+Del are pressed. Usually, the file contains something like this:

$ cat /etc/inittab
...
# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
...

So, in runlevel 1-5, the command "shutdown" is to be executed when someone press Ctrl+Alt+Del. It could be changed to anything we'd like. We would like to log the incident and issue a warning to the user on the console:

ca:12345:ctrlaltdel:/usr/bin/logger -t init -s "Ctrl+Alt+Del pressed on console. Use normal shutdown routines."

When someone now tries the "three finger salute", they'll be told to use "normal shutdown routines". The incident are also logged:

# tail -1 /var/log/messages
Mar 12 20:50:19 titan INIT: Ctrl+Alt+Del pressed on console. Use normal shutdown routines.

Update! - Newer Ubuntu uses Upstart and things are a little different. You don't define what action to be taken in /etc/inittab (it no longer exists), but we have to modify a file in /etc/event.d/:

# cat /etc/event.d/control-alt-delete
# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination
# is pressed.  Usually used to shut down the machine.

start on control-alt-delete

#exec /sbin/shutdown -r now "Control-Alt-Delete pressed"
/usr/bin/logger -t init -s "Ctrl+Alt+Del pressed on console. Use normal shutdown routines."

No comments: