FriconiX
Free collection of beautiful vector icons for your web pages.

How to use logkeys (keyboard sniffer) on Ubuntu?

Logkeys is a keyboard logger for Linux. You can install logkeys by following the instructions on the logkeys installation page.

The following has been performed with the following versions:

Check

Run the following command to check that logkeys is properly installed:

logkeys -?

The previous command should display help page.

Find your keyboard

The following command will display each input device details:

cat /proc/bus/input/devices

I'm not fully sure, but I think the first device displayed is /dev/input/event0, the second one is /dev/input/event1 and so one.

Be carrefull if you have several keyboards to pick the right one. In my case, I have a desktop keyboard (/dev/input/event5) connected to a laptop (/dev/input/event3). In the following, I will log the desktop keyboard on /dev/input/event5.

Start logging

The following command starts recording key pressed and stores the keys in the file log-keyboard.txt located in my home directory:

sudo logkeys -s -o ~/log-keyboard.txt -d event5

Modify the previous command according to the right event file and path to the desired log file.

Specific layout

If you want a specific layout, you have to specify it with the -m option. There is a list of available keymaps on the logkeys repository. If your keyboard is not in the list, you can create your own layout by following the instructions on this page.

For example, if you want the French layout, download the French keymap and run the following command:

sudo logkeys -s -o ~/log-keyboard.txt -d event5 -m /path/to/file/fr.map

Log file

Since the command is launched with root permissions, only users with root permissions can display the log file. The following command display the log file with recorded keys inside:

sudo cat log-keyboard.txt 

Stop logging

The following command stops recording the keys:

sudo logkeys -k

See also


Last update : 12/07/2019