5

Is it possible to execute Magic SysRq keys on remote machine, using SSH? For example I'm trying to run like this:

xdotool key Alt+Sys_Req+H

But I do not see any help in console, neither in /var/log/syslog.

Please assume that I do not have root access, and I can't write to /proc/sysrq-trigger.

  • If it was possible without root access, you'd have a big security hole. – Stéphane Chazelas Feb 20 '14 at 9:29
  • I was thinking that it is possible to send keystrokes via ssh. I'm using Ubuntu, here I can press Alt+SysRq+H as usual user, not root, and get help message. – c0rp Feb 20 '14 at 9:37
  • But you're a physical user typing on a USB keyboard connected to the machine, not some random unprivileged process on the system. Note that most systems restrict what sysrq keys are accepted over the keyboard as well. – Stéphane Chazelas Feb 20 '14 at 9:43
  • Thanks! If you write this information in answer, I will be able to mark question as answered – c0rp Feb 20 '14 at 9:45
7

This should work if sysrq is enabled in the kernel (tested live on my machine):

# echo "h" > /proc/sysrq-trigger

Requires root access.

The SysRq keys are not regular keys handled by X, thus xdotool can't trigger the magic keys because it interacts with Xorg itself, not the kernel. Thankfully the kernel provides a special file to trigger them from scripts and remote shells.

Tested on mine with an emergency sync command (S):

# echo "s" > /proc/sysrq-trigger
# dmesg | tail -n 2
[263565.001982] SysRq : Emergency Sync
[263565.115168] Emergency Sync complete
2

I was curious to see if you could inject the SysRq keypress using the Linux uinput device, so I added some code to another small project and it seems to be possible. But as was already noted, of course you need to have root access for this as well.

For this particular key combination, I'd have to execute:

./sendevtkeys /dev/uinput 56 99 35

where 56 corresponds to Alt, 99 to SysRq and 35 to h.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.