I had a really bad lockup of my X server and had to do a Sys Rq + r to release my keyboard from X and get into a console. I was able to kill the process that was locking up my system, and continue my work in my still running X server.

Now whenever I e.g. push Alt + F4 to kill a window, my system switches to the 4th console instead of killing the active window. So it seems that my keyboard still is in released mode.

How do I undo my previous Sys Rq + r command, such that I can continue my work in my running X server?

2 Answers 2


I found the solution myself just after asking this question.

To switch back the console in which X is running (usually tty7), from ASCII mode to RAW mode execute the following command:

sudo kbd_mode -s -C /dev/tty7

And now everything works as expected again. :)

More information available in the question: What does raw/unraw keyboard mode mean?

  • Thanks! Still trying to figure out if there's a way to do it for all ttys at once, the same way unRaw does... Nov 1, 2015 at 13:58
  • 3
    @phyzome You don't want to do this for all ttys, as the "normal" (text-mode) tty expects ASCII (XLATE) or UTF-8 (UNICODE) mode. Otherwise you can't type there (that's just what SysRq-R fixes). For fun, try kbd_mode -s -C /proc/self/fd/0 on a tty, see it break, then fix it by SysRq-R.
    – nobody
    Dec 1, 2016 at 22:25
  • 1
    If you are using the TTY that X is running in, you can also use sudo kbd_mode -s -C /dev/tty$(sudo fgconsole). May 31, 2018 at 22:34

If you find yourself searching the web for this particular command more than once (like I've done) you can use the following shell script to recapture the keyboard to the TTY in use:


function ttys() {
    # find open files named `/dev/tty?` from commands named `Xorg`
    lsof -Fn -c Xorg -a /dev/tty? | \
      egrep '^n' |                  \
      sed -r 's/^n(.+)$/\1/g' |     \
      sort |                        \

count_ttys=$(wc -l <<< $tty )

if [[ $count_ttys -gt 1 ]]; then
  echo 'more than one tty in use, exiting'
  exit 1

echo binding keyboard to $tty
sudo kbd_mode -s -C $tty

You must log in to answer this question.

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