Automate KeePass database sync with Google Drive on Linux

I’ve been using KeePass as my preferred Password Manager for a long time. Using the same KeePass database file on multiple devices (Computer, Tablet, Phone) I was in need to find a location to put the KeePass database file in the cloud to be used as a source. I choose Google Drive.

Besides Linux, for all other operating systems, there where easy solutions to automatically sync the KeePass database file with my device. Unfortunately for Linux that was not the case 🙁

I was close giving up on getting my KeePass database file automatically synced with Google Drive on Linux when I came across a Reddit post. User „xcheet“ described how he/she managed to get the KeePass database file synced automatically on Linux.

At first, it seemed a lot of steps to perform to get the sync working. Luckily I did give it a try and it was worth the time! It works!

You find the original instructions on Reddit here.

Just in case, the reddit post gets deleted, I will put the steps down below.

Part 1, Prerequisits

1. You need to install „drive“. You can either install it using Github or use Johnathan Jenkins PPA.

sudo add-apt-repository ppa:twodopeshaggy/drive
sudo apt-get update

2. Now you need to initialise „drive“. Create a folder, which will be used to store the local copy e.g. gdrive

mkdir ~/gdrive
drive init ~/gdrive

3. Because drive doesn’t allow KeePass to modify the database file directly on the server, you need to split the down- and upload process and use a local copy. The drive commands only work when the working directory is the folder that drive was initialized in.

cd ~/gdrive
drive pull keys.kdbx

I decided to put the copy into the Documents folder.

mkdir -p ~/Documents/KeePass
cp ~/gdrive/keys.kdbx ~/Documents/KeePass

Part 2, Prepare Triggers

4. In order to update your local copy, you need two scripts in your ~/Documents/KeePass folder: keepass_trigger_load.sh and keepass_trigger_save.sh

  • keepass_trigger_load.sh changes the working directory to the drive folder and pulls the database from the server.
  • keepass_trigger_save.sh copies the database from the Documents folder to the drive folder and then uploads it.
# keepass_trigger_load.sh
cd ~/gdrive
drive pull -ignore-conflict -quiet keys.kdbx
# keepass_trigger_save.sh
cp ~/Documents/KeePass/keys.kdbx ~/gdrive
cd ~/gdrive
drive push -ignore-conflict -quiet keys.kdbx
chmod +x ~/Documents/keepass_trigger_load.sh
chmod +x ~/Documents/keepass_trigger_save.sh

Part 3, Add Triggers in KeePass

5. The last part covers how to create and configure the KeePass triggers. We meed two triggers, one which pulls and synchronises with the local KeePass database copy.

The second trigger is activated every tome the local copy is opened, the server copy will then be pulled and synchronized with the local copy.

Instead of creating both triggers manually, you should use xcheets version provided on Pastebin.

If you decide to use his trigger example as a template, you will need to change the file paths to match the way it’s set up on your system.

Copy the example to your clippboard and then insert it using Tools -> Triggers -> Tools -> Paste Triggers from Clipboard.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.