I have written a Python script that I would like to run in the background on my Raspberry Pi. The script makes use of the Python module Keyring
(link), which is used to access a keyring backend to provide password input to the script.
I wrote the script in OS X, for which Keyring
makes use of OS X Keychain. But on a headless Raspberry Pi not using X11
, something like GNOME Keychain
must be installed to act as the backend.
I have read the Pypi instructions (referenced below), but I am unfamiliar with D-Bus
and how to make it all work in practice. Would anyone be willing to provide a practical example of how D-bus
and the GNOME Keyring
may be handled by Raspbian
, assuming this:
- The script should always run in the background as long as the Raspberry is powered on, and it is invoked via
crontab
. - The script should run from a
virtualenv
environment, which has theKeyring
module installed. - Handling of the
GNOME Keyring
/D-Bus session
is handled as automatically as possible, and can provide the keyring entries to the script without user input (e.g. loaded automatically when the Raspberry is powered on, or the script is executed).
https://pypi.python.org/pypi/keyring#using-keyring-on-headless-linux-systems
Using Keyring on headless Linux systems
It is possible to use the SecretService backend on Linux systems without X11 server available (only D-Bus is required). To do that, you need the following:
Install the GNOME Keyring daemon. (Note: I have done this via
apt-get
).Start a D-Bus session, e.g. run
dbus-run-session -- sh
and run the following commands inside that shell.Run
gnome-keyring-daemon
with--unlock
option. The description of that option says:Read a password from stdin, and use it to unlock the login keyring or create it if the login keyring does not exist.
When that command is started, enter your password into stdin and press Ctrl+D (end of data). After that the daemon will fork into background (use
--foreground
option to prevent that).Now you can use the SecretService backend of Keyring. Remember to run your application in the same D-Bus session as the daemon.