Skip to content

Instantly share code, notes, and snippets.

@dAnjou
Last active November 26, 2024 02:14
Show Gist options
  • Save dAnjou/b99f55de34b90246f381e71e3c8f9262 to your computer and use it in GitHub Desktop.
Save dAnjou/b99f55de34b90246f381e71e3c8f9262 to your computer and use it in GitHub Desktop.
Automatically unlock KeePass database with GNOME Keyring

(Tested with KeePassXC on Fedora 25)

By default when using GNOME Keyring you have a keyring that is unlocked when you log in (usually called "Login"). You can make use of that by storing a KeePass database password in this keyring and using it to automatically unlock your KeePass database.

Store the KeePass database password in GNOME Keyring. You'll have to set a label and at least one attribute/value pair. The label is displayed in a GNOME keyring manager (e.g. Seahorse), the attribute/value pair should be a unique identifier because it's needed for the lookup. I suggest to use keepass as attribute and the database name as value (make sure it doesn't contain any spaces).

secret-tool store --label="KeePass <database_name>" keepass <database_name>

Then create a script to launch and immediately unlock your KeePass database.

#!/bin/bash

secret-tool lookup keepass <database_name> | keepassxc --pw-stdin /path/to/<database_name>

You can now use this script to launch KeePass with your database already unlocked. I recommend to create a desktop launcher for more convenience.

@Organic-Marble
Copy link

This works for me on Ubuntu Linux in that it starts KeePassXC and unlocks the database. But there's still a prompt to enter a password in the terminal window, and the script doesn't proceed. Any thoughts?

@RamiShafikovca
Copy link

RamiShafikovca commented Nov 14, 2023

@Organic-Marble Sorry for the late message, I found that switching the order of the argument works:
keepassxc /path/to/<database_name> --pw-stdin
So the command should read:
secret-tool lookup keepass <database_name> | keepassxc /path/to/<database_name> --pw-stdin

@erenfro
Copy link

erenfro commented Nov 26, 2024

I've done a little extra thing and gone ahead and done this: https://github.com/erenfro/keepassxc-unlocker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment