Syncing keepass database between android and desktop with rsync

By Krolyxon2 minutes read

Archived

This post has been archived on 2025-06-22.

Introduction to keepass

Everyone should use password managers, because remembering unique passwords is difficult. There are many great FOSS password managers such as Bitwarden, Keepass, KeepassXC etc. I wouldn’t recommend using Bitwarden because its cloud based, Your password database is being stored in cloud, and it makes me really paranoid, since there are thousands of users using it, lots of hackers are always trying to break into Bitwarden’s server and potentially leak the passwords.. Even though Bitwarden allows you to self-host your own vault, i still feel paranoid about having my password database have anything to do with the internet. So instead, i go with KeepassXC because it is completely localized and offline. You can read the installation instructions and read more about it on keepassxc.org However, we are going focus more on how to sync the password database created from Keepassxc on your desktop and cellphone(android).

After you are done installing Keepassxc on your desktop, install keepassdx on your cellphone, To access your encrypted password database from your cellphone.

Sync the database between both devices.

  1. Install rsync and ssh(obviously…) on your desktop.
  2. Install termux on your cellphone.
  3. install rsync & openssh on termux by running pkg install openssh rsync
  4. start ssh server on termux by running sshd
  5. get your local ip adress of your cellphone by running ifconfig

Once you are done with that, go to the terminal on your desktop and run this command:

rsync -vrP --delete --rsh='ssh -p 8022' ~/passdb/on/desktop.kbdx username@ip:passdb/on/cellphone.kbdx

here i specify the port with --rsh='ssh -p 8022' because specifying it with --port flag didng work for me. repace your username with your username and local ip adress of termux in username@ip. and repace the paths in the commands to where your password database is stored in your desktop and cellphone. and here we go, it will sync the database.

However, i wanted to go further and make it a bit automaticish, so i ended up with this script.

#!/bin/sh
# paths of database file locations in android and desktop
anpath="storage/shared/path/to/pass-database.kdbx"
deskpath="path/to/pass-database.kdbx"

# getting last modified date
desktop=$(stat -c%Y $deskpath)
android=$(ssh android -t stat -c%Y $anpath)

# syncing the database between both devices by calculating
# in which device the password database was last modified.
# not syncing anything if there was no change.
if [ $android -lt $desktop ]; then
  echo "transferring from desktop to android"
  rsync -vrtP $deskpath android:$anpath
elif [ $desktop -lt $android ]; then
  echo "transferring from android to desktop"
  rsync -vrtP android:$anpath $deskpath
elif [ $desktop -eq $android ]; then
  echo "nothing was modified, not syncing"
fi

When i run this script, it will check in which device i had the password database last modified, and sync the password database from desktop to cellphone if it was last modified on my desktop computer and vice versa.