Desktop Environment (if applicable):
None. This machine will never be loaded with a desktop GUI.
Problem Description:
When I login I’d like use dvorak keyboard in my user session. That seems like a fairly reasonable request which I can accomplish using
sudo loadkeys dvorak
However, I’d really like to have this happen automatically. I’d like to be able to include a command in my .bashrc that says, “please let me use my keyboard” without needing to interact with passwords.
There is some advice about using commands that are included with the desktop environments. This server doesn’t have a desktop environment, and I don’t want to start installing extra code.
What I’ve Tried:
I’ve been looking online expecting to find a simple command to achieve this. The choice of keyboard seems like such a user-centric thing that I’m surprised that there isn’t a user-level command to achieve it? Loadkeys is effective, I just find it annoying to have to work so hard to configure my session.
The reason for the need to use sudo in this case can be found in the man-page for loadkeys. loadkeys changes the keyboard translation table in the kernel, meaning any changes you make persist beyond your session (but not beyond a reboot) - the next person to login will have to work with dvorak layout. If this is a personal server sitting at home that’s not a big deal, but in any environment where a lot of different people might have to work with this server changing the keyboard layout is not a nice thing to do.
If it is a personal server and you want to change the keyboard layout permanently, you can run sudo dpkg-reconfigure keyboard-configuration
If it’s not a personal machine, things get more complicated. You’d have to change /etc/sudoers (please, do use ‘visudo’ for that; it checks the edited file for mistakes which would make ‘sudo’ unusable) to allow you to execute ‘sudo loadkeys’ without a password (so it will run from a script without asking for a password) and you really should set up a ~/.bash_logout file to set the keyboard back to what other users expect when you log out…
I noticed that loadkeys was doing much more than I wanted when I found the system accepting dvorak at the login prompt. I was hoping for a solution that wouldn’t affect other users while I am logged in.
Fortunately I’ve realised that the problem has evaporated. I was attaching a keyboard directly to the server to install the system. In that situation I did need to modify the keyboard. I’m normally getting remote access via SSH. When I’m on my own machine, as I am now, the server doesn’t know and doesn’t care what keyboard map I’m using, so there’s no need for me to mess around with alternative keyboards on the server.