3

I switch between Dvorak and QWERTY keyboard layouts and frequently find myself with mismatched layouts on my host operating system and a Linux virtual machine.

How can I easily switch the layout when I have the wrong layout set?

Note that I'm talking about the command-line-only system console here, not a terminal window in a GUI.

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Steve HHH
  • 6,960
  • 6
  • 29
  • 37
  • This might also be helpful http://superuser.com/questions/598405/how-do-i-switch-to-dvorak-across-multiple-oss#comment741771_598405 – William Jun 01 '13 at 19:15

1 Answers1

6

I found the solution to be to create the following aliases in my .bashrc file:

alias asdf="sudo loadkeys dvorak"
alias aoeu="sudo loadkeys us"

Now, when I find myself with the wrong layout, I type the same four keys on the home row to switch layouts.

The only issue I had with this was that it could be difficult to enter a password for the sudo command when the wrong layout is enabled. There are two solutions to this problem, but they may be a security issue in some environments:

  1. Use a strong-ish password comprised only of numbers, symbols, and the letters M and A (they're the same for both Dvorak and Qwerty).

  2. Set the suid bit on /usr/bin/loadkeys so it automatically runs as root (and you don't need to run it with sudo). I used the command sudo chmod u+s /usr/bin/loadkeys. Note: I needed to install the console-data package beforehand.

Edit: added excellent suid suggestion from ssmy.

Steve HHH
  • 6,960
  • 6
  • 29
  • 37
  • 1
    Nice password workaround. Might be a security issue, but maybe loadkeys can be set suid? – ssmy Feb 08 '13 at 05:23
  • Yeah, my password suggestion would not cut mustard in a production environment. On my personal systems, I always disable SSH password access to force RSA key authentication, and so only type a password either for `sudo` or when on the system console. – Steve HHH Feb 08 '13 at 07:07