Change keyboard layout in linux console

Change keyboard layout (English UK) on command line to English US

I am using Ubuntu 12.04. The keyboard layout is English US everywhere except for the Command Line where it works in English UK. Terminal also has English US. How do I change the default keyboard layout in Command Line to English US? Also, I think it might be worth noting here, that when I had installed Ubuntu (dual boot with Windows 8. 1), I had initially set the language as English UK, but later changed it to English US from the system settings.

@terdon I think you second guessed yourself, Ctrl+Alt+F2 should indeed be a virtual terminal (the ‘Run Dialog’ is plain Alt+F2). I’m not sure if console-setup is installed by default, but perhaps the OP should try sudo dpkg-reconfigure console-setup ?

@steeldriver you are absolutely correct, I did not notice the Ctrl! Thanks, that makes this answerable!

7 Answers 7

Update 2017-04-13: This seems to have changed in recent Ubuntu versions and running sudo apt-get install console-common will try to remove other packages. So, for recent Ubuntu versions, use this instead (Tested in 17.04):

sudo dpkg-reconfigure keyboard-configuration 

The simplest way would indeed be as @steeldriver suggested to open a terminal and run this command:

sudo apt-get install console-common 

That will install the console-common package and in the process allow you to chose your console layout. If that is already installed, use this to bring up the same wizard and set the layout:

sudo dpkg-reconfigure console-data 

Tested on 13.10, and taken from here.

Using Ubutnu 14.04 I was able to set the keyboard on a text-console. But after a reboot it would be reset to the previous settings. Only after issuing a sudo dpkg-reconfigure keyboard-configuration I was able to set it permanently.

Seems like a bit of kludge to do something so seemingly simple — but hey, it worked on a Raspberry PI (running raspbian), so cool, thanks.

This doesn’t work anymore with 16.04. Installing console-common wants to remove packages cryptsetup, plymouth, lightdm, and some others. dpkg-reconfigure keyboard-configuration does work however.

Goddamn it. After I ran this command and reboot, it stuck at the purple blank screen. Turns out this command also removed plymouth and unity. @OlafDietsche is right!

The above didn’t work for me, but this did. From terminal enter the following command:

This worked for me when using Chrome Remote Desktop to Mint even though the keyword layout is correct when logged in normally.

sudo dpkg-reconfigure keyboard-configuration 

Yes, running 16.04 (Thinkpad T430) and sudo dpkg-reconfigure keyboard-configuration worked a treat for me. Did not have to reboot just chose Generic 105 Int Keyboard and UK layout to recover my Keyboard after it had mysteriously change to US layout. Thanks

I have a console only (without X) Linux running inside a VirtualBox. Needed to change layout from US keyboard to a German one. I used loadkeys (load keyboard translation tables by kbd package):

To make it permanent use systemd’s localectl:

set-keymap MAP [TOGGLEMAP]
Set the system keyboard mapping for the console and X11. This takes a mapping name (such as «de» or «us»), and possibly a second one to define a toggle keyboard mapping. Unless —no-convert is passed, the selected setting is also applied as the default system keyboard mapping of X11, after converting it to the closest matching X11 keyboard mapping. Use list-keymaps for a list of available keyboard mappings (see below).

See also

Thanks to you I found the solution for me, running my server in VNC. Your command changes it temporarily. To make it permanent I used localectl set-keymap de .

Читайте также:  Свой сервер css v34 linux

Thanks. This works on a fresh server 16.04 install out of the box. The above setxkbmap solution requires to install some X11 utils, which IMHO did not seem the right thing to do on a server.

I’m running 14.04 LTS with a standard US keyboard. My problem was that I had relied on the installer to choose US-Intl for me and it caused «dead keys» and improper formation of the » and ‘ keys (as well as others I don’t know about, I’m sure).

After a lot of frustration and trial and error, I ran the » sudo apt-get install console-common » suggestion and it fixed my problem, but only while I was logged in.

When I logged out, restarted the server and back in, it failed.

It only took hold permanently when I executed the » sudo dpkg-reconfigure keyboard-configuration » command and specified the generic US keyboard.

» setxkbmap » did not work for me.

It seems that (I don’t KNOW) setxkbmap is obsolete in 14.04 LTS.

Источник

Linux console/Keyboard configuration

Keyboard mappings (keymaps), console fonts and console maps for the Linux console are provided by the kbd package (a dependency of systemd), which also provides many low-level tools for managing text console. In addition, systemd also provides the localectl tool, which can control both the system locale and keyboard layout settings for both the console and Xorg.

Viewing keyboard settings

Use localectl status to view the current keyboard configurations.

Keymaps

The keymap files are stored in the /usr/share/kbd/keymaps/ directory tree. Usually one keymap file corresponds to one keyboard layout (the include statement can be used to share common parts and a keymap file can contain multiple layouts with some key combination used for switching). For more details see keymaps(5) .

Listing keymaps

The naming conventions of console keymaps are somewhat arbitrary, but usually they are based on:

  • Language codes: where the language code is the same as its country code (e.g. de for German, or fr for French).
  • Country codes: where variations of the same language are used in different countries (e.g. uk for United Kingdom English, or us for United States English); a list of country codes can also be found in wikipedia:ISO 3166-1#Officially assigned code elements.
  • Keyboard layouts: where the layout is not related to a particular country or language (e.g. dvorak for the Dvorak keyboard layout).

For a list of all the available keymaps, use the command:

To search for a keymap, use the following command, replacing search_term with the code for your language, country, or layout:

$ localectl list-keymaps | grep -i search_term 
$ find /usr/share/kbd/keymaps/ -type f -name "*search_term*"

Loadkeys

It is possible to set a keymap just for current session. This is useful for testing different keymaps, solving problems etc.

Читайте также:  Comodo antivirus для linux установка

The loadkeys tool is used for this purpose, it is used internally by systemd when loading the keymap configured in /etc/vconsole.conf . It can be used very simply for this purpose:

Persistent configuration

A persistent keymap can be set in /etc/vconsole.conf , which is read by systemd on start-up. The KEYMAP variable is used for specifying the keymap. If the variable is empty or not set, the us keymap is used as default value. See vconsole.conf(5) for all options. For example:

For convenience, localectl may be used to set console keymap. It will change the KEYMAP variable in /etc/vconsole.conf and also set the keymap for current session:

# localectl set-keymap --no-convert keymap 

The —no-convert option can be used to prevent localectl from automatically changing the Xorg keymap to the nearest match. See localectl(1) for more information.

If required, the keymap from /etc/vconsole.conf can be loaded during early userspace by the keymap mkinitcpio hook.

  • If you saved your custom keymap somewhere other than /usr/share/kbd/keymaps/ , it must be specified by a full path to the file in vconsole.conf or when using the localectl command above.
  • The XKB* variables in /etc/vconsole.conf are for Xorg/Keyboard configuration. loadkeys does not yet support using them; see kbd issue 72. And neither does Xorg.

Creating a custom keymap

When using the console, you can use hotkeys to print a specific character. Moreover we can also print a sequence of characters and some escape sequences. Thus, if we print the sequence of characters constituting a command and afterwards an escape character for a new line, that command will be executed.

One method of doing this is editing the keymap file. However, since it will be rewritten anytime the package it belongs to is updated, editing this file is discouraged. It is better to integrate the existing keymap with a personal keymap. The loadkeys utility can do this.

First, create a keymap file. This keymap file can be anywhere, but one method is to mimic the directory hierarchy in /usr/local : create the /usr/local/share/kbd/keymaps directory, then edit /usr/local/share/kbd/keymaps/personal.map .

As a side note, it is worth noting that such a personal keymap is useful also to redefine the behaviour of keys already treated by the default keymap: when loaded with loadkeys , the directives in the default keymap will be replaced when they conflict with the new directives and conserved otherwise. This way, only changes to the keymap must be specified in the personal keymap.

  • You can also edit an existing keymap located in the /usr/share/kbd/keymaps/ directory tree. Keymaps have an .map.gz extension, for example us.map.gz is an American keymap. Just copy the keymap to /usr/local/share/kbd/keymaps/personal.map.gz and gunzip it.
  • The custom keymap can be made persistent by setting it in /etc/vconsole.conf . Given this, if you use the sd-vconsole mkinitcpio hook instead of keymap , you could place your custom keymap file in /usr/share/kbd/keymaps/ . This way its dependencies from /usr/share/kbd/keymaps will be automatically added to the initial ramdisk image by the hook. On the other hand, if you place your custom keymap file under /usr/local/ , then its dependencies will need to be manually specified in the FILES array in mkinitcpio.conf .
Читайте также:  Проверка подключенных устройств linux

Adding directives

Two kinds of directives are required in this personal keymap. First of all, the keycode directives, which matches the format seen in the default keymaps. These directives associate a keycode with a keysym. Keysyms represent keyboard actions. The actions available include outputting character codes or character sequences, switching consoles or keymaps, booting the machine, and many other actions. The full currently active keymap can be obtained with

Most keysyms are intuitive. For example, to set key 112 to output an ‘e’, the directive will be:

To set key 112 to output a euro symbol, the directive will be:

Some keysym are not immediately connected to a keyboard actions. In particular, the keysyms prefixed by a capital F and one to three digits (F1-F246) constituting a number greater than 30 are always free. This is useful directing a hotkey to output a sequence of characters and other actions:

Then, F70 can be bound to output a specific string:

When key 112 is pressed, it will output the contents of F70. In order to execute a printed command in a terminal, a newline escape character must be appended to the end of the command string. For example, to enter a system into hibernation, the following keymap is added:

string F70 = "sudo systemctl hibernate\n"

Other examples

  • To make the Right Alt key same as Left Alt key (for Emacs), use the following line in your keymap. It will include the file /usr/share/kbd/keymaps/i386/include/linux-with-two-alt-keys.inc , check it for details.
include "linux-with-two-alt-keys"
keycode 1 = Caps_Lock keycode 58 = Escape
keycode 29 = Caps_Lock keycode 58 = Control

Saving changes

In order to make use of the personal keymap, it must be loaded with loadkeys:

# loadkeys /usr/local/share/kbd/keymaps/personal.map

However this keymap is only active for the current session. In order to load the keymap at boot, specify the full path to the file in the KEYMAP variable in /etc/vconsole.conf. The file does not have to be gzipped as the official keymaps provided by kbd .

Adjusting typematic delay and rate

The typematic delay indicates the amount of time (typically in milliseconds) a key needs to be pressed and held in order for the repeating process to begin. After the repeating process has been triggered, the character will be repeated with a certain frequency (usually given in Hz) specified by the typematic rate. These values can be changed using the kbdrate command. Note that these settings are configured separately for the console and for Xorg.

# kbdrate [-d delay] [-r rate]

For example to set a typematic delay to 200ms and a typematic rate to 30Hz, use the following command:

Issuing the command without specifying the delay and rate will reset the typematic values to their respective defaults; a delay of 250ms and a rate of 11Hz:

Systemd service

A systemd service can be used to set the keyboard rate. For example:

/etc/systemd/system/kbdrate.service
[Unit] Description=Keyboard repeat rate in tty. [Service] Type=oneshot RemainAfterExit=yes StandardInput=tty StandardOutput=tty ExecStart=/usr/bin/kbdrate --silent --delay 250 --rate 30 [Install] WantedBy=multi-user.target

Then start/enable the kbdrate.service systemd service.

Источник

Оцените статью
Adblock
detector