Command-line access to GNOME keyring

gnome-keyringA few days back I suddenly needed to access GNOME keyring from a command-line, to be used in my backup script. Of course I can save my passwords in plaintext in files like .netrc, but why should I, when all my passwords are already stored securely in the GNOME keyring? I have googled and googled and found nothing, there is no tool for accessing GNOME keyring from shell (until now). But I have found a simple Python module though (kudos to Sebastian Rittau).

I’m a complete beginner with Python, but I said ‘Hey, that’s a good opportunity to learn it a little bit!’.  So I present you my outstanding result, the gkeyring project: 🙂

https://launchpad.net/gkeyring

Retrieving your secrets is as simple as:

$ ./gkeyring.py get -s myserver.com -p ftp -u user

This will look for all keyring items concerning server myserver.com with protocol ftp and username user. Note: Currently the script is only able to access network passwords (which is what I needed).

The first time you access the keyring item you will be prompted whether to allow the script to access it. You can click “Always” and then it won’t ask again. Finally you just cut the output a little and you are done! Ready to be used in your script.

Hope that helps someone (it does help me). If you feel like improving the script, please do!

9 thoughts on “Command-line access to GNOME keyring

  1. Hi, Neat post. There’s a problem along with your website in web explorer, would check this? IE still is the market leader and a big element of other people will leave out your wonderful writing because of this problem.

    1. Thanks for info, but this is hosted at WordPress, I don’t manage it. So please report all IE-related problems to WordPress, if you so desire. Personally I don’t care much, IE users and Linux users are quite disjoint groups.

Leave a Reply (Markdown syntax supported)