17

Suppose I boot a Linux machine without GUI. When it displays a tty login prompt, can I shutdown the machine with a keyboard sequence?

Of course I could type in my username and password and then sudo shutdown -h now; however, is it possible to shut it down before the login using a keyboard shortcut?

4 Answers 4

16

On most Linux systems, the Ctrl+Alt+Del key sequence action is configured in either /etc/inittab or /etc/init/control-alt-delete.conf.

Usually, this will reboot the system, but you could modify the command to halt the system instead.

In /etc/inittab:

ca::ctrlaltdel:/sbin/shutdown -t3 -h now

Or /etc/init/control-alt-delete.conf:

start on control-alt-delete    
exec /sbin/shutdown -h now "Control-Alt-Delete pressed"
1
  • Can I also use another key sequence for this? (I don't want to overwrite the reboot thing)
    – student
    Commented Aug 9, 2012 at 7:27
11

I've done this before with a user named "s" and no password.

IIRC you set the user's shell to /sbin/shutdown. Prolly need to add it to /etc/shells.

9

Here's a nice little trick that kind of surprised me (life saver if you freeze a remote system with no iLO (or KVM). The Magic SysRq key. If it is active on your system, I believe hitting ALT + SysRq + o should turn off your system. This is a hard shutdown (if I recall correctly, don't want to test it right now!) so you can press: ALT + SysRq + e (nicely kill all processes) ALT + SysRq + i Kill everything else) ALT + SysRq + s sync all file systems, ALT + SysRq + u to remount partitions as read only, then do the b or o combination (reboot or shutdown)

Anyway, I don't think this is the best way to halt your system, the other answers may be more suitable, but the above should help you out if your stuck!

2
  • 7
    Although this works, it's a little bit like stopping your car by driving it into a pile of hay. Effective, and your car will probably be okay afterward.
    – bahamat
    Commented Aug 9, 2012 at 0:58
  • 2
    I 100% agree with you, I tried to make that clear in my answer. If you do the key combination in the right way it is a little bit better, but yes, this is a shiny red button that does what it says and not much else.
    – Rqomey
    Commented Aug 9, 2012 at 6:49
3

Many Linuxes perform a clean shutdown in response to a short press of the power button, if the power button is not handled by a graphical interface.

This behaviour has been adopted by default in systemd (implemented by systemd-logind). Even before then, it was implemented in some Linuxes default configuration of acpid. The exact behaviour may vary a bit.

This requires that short presses of the power button can be handled in software. This hardware feature is supported by the ACPI standard. (Of course you could be ACPI compliant and still have some button that shuts the system down immediately and uncleanly).

1
  • thanks, why is the simple, obvious solution so underappreciated ^^
    – xeruf
    Commented Oct 13, 2022 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .