Auto-typing passwords in X11

28 January 2015
Normally when I use SSH I make use of DSA keys, but part of my job involves frequent fresh installations of server clusters which at the moment only include default passwords. Remembering which one of half a dozen or so that are in use by the project is the correct one for a given circumstance is difficult enough, but factor in mistypes and thigns get annoying very quickly. Cut'n'pasting was also getting a little tedious, so I looked for a way that I could bind the typing of a password to a key. The best solution I found was XMacro, which works by injecting keyboard and mouse events into the X11 connection to the X-Server.

The most recent available version is pre0.3 which is clearly a beta versions from mid-2001, and by the looks of things omits any sort of configure script. You will need to add -DHAVE_IOSTREAM to the Makefile to get it to build with a modern compiler, and then once its built manually copy xmacroplay it to a suitable location (e.g. /usr/local/bin). Next step is then to create a shell (e.g. passwords.sh) script that calls it, passing in a fabricated macro file that contains the password key-presses:

#!/bin/bash echo String $* | /usr/local/bin/xmacroplay :0

Rather than bind this script to a key, I decided to bind it to a program menu item. In IceWM this is done by editing ~/.icewm/menu and adding the following (and no, the passwords here are not ones I use..):

menu "Echo Password" folder {    prog Sekret /usr/share/icons/hicolor/16x16/status/bluetooth-paired.png /usr/local/bin/passwords.sh Sekret    prog Magick /usr/share/icons/hicolor/16x16/status/bluetooth-paired.png /usr/local/bin/passwords.sh Magick }

Feeel free to use an alternativem icon - bluetooth-paired.png just happened to look like a key. If successful, you should have an Echo Password sub-menu:

If you have setup IceWM so that focus follows the mouse, you might need to increase the delay in passwords.sh so that you have time to bring the target window back into focus. If you want instead use a key, edit ~/.icewm/keys and add the following:

key "Ctrl+F1" /usr/local/bin/passwords.sh Sekret

Avoid using the shift key, as the chances are that all the password key-presses will get registered before you release it, making the entire password upper-case. You will need to restart IceWM before the new key bindings take effect, although this can be done without restarting all your other programs.