Is it possible to create a keyboard shortcut that will run:
shutdown -h now
When I press Ctrl + 9, for example.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIs it possible to create a keyboard shortcut that will run:
shutdown -h now
When I press Ctrl + 9, for example.
Something pretty similar does probably already work: see SysRq key sequences (see also the Linux kernel documentation). Some variant of REISUB
, maybe REISUO
(O
for poweroff instead of B
for reboot) could be what you want.
Not as quick and versatile as a way of binding Ctrl+9 to any command, but a possibility.
You can define two such shortcuts on the Linux console. Pressing Ctrl+Alt+Del sends the SIGINT signal to init
; this triggers the ctrlaltdel
action in inittab
. This action usually triggers /sbin/shutdown -t1 -a -r now
(reboot now); change that to /sbin/shutdown -t1 -a -h now
if you want to halt instead. The other shortcut is the KeyboardSignal
console key (bound to Alt+Up by default, but you can change that in your console keymap), which triggers the kbrequest
action in inittab.
Note that these bindings may not be triggered while you're in X. Under X, you can use your window manager's key binding features, or another program such as xbindkeys. Note that under X, you don't get a free pass to run commands as root; if you want to trigger a reboot without entering a password, you'll need a NOPASSWD
entry in sudoers
.
(Aside: Ctrl+9 looks awfully easy to type by mistake. It's also a keyboard shortcut in several applications. Pick something rarer and with two modifiers!)
inittab
can be overridden by your WM/DE/OS. If you want it to be truly global, you will need to also configure your environment to allow it to act as so.