Linux – How to use setxkbmap from tty

keyboard-layoutlinuxx11

I'm confused about using setxkbmap. When I use it in my terminal emulator under X, it works:

setxkbmap -layout gr -option # switches layout to greek

However, if I switch to tty2, execute the command (with proper DISPLAY set) and switch back to X, layout does not change:

DISPLAY=:0 setxkbmap -layout gr -option

What am I doing wrong?

Best Answer

The X server must be active when you execute that command from a TTY.

export DISPLAY=:0 # Your Display
sleep 1 && setxkbmap us # Change keyboard layout

So I recommend you to execute that command and then, immediately switch to your X display for the changes to be applied.

You can see this behaviour on the xclip -o command. When executed on the TTY, it waits before the X server is active to print out the content of the primary clipboard.

Related Question