Skip to main content

A simple command line tool to interact with KeePassX databases

Project description

https://github.com/rebkwok/kpcli/workflows/Run%20tests/badge.svg

kpcli

A simple command line tool to interact with KeePassX databases.

KeePassX is a cross platform password management application. It is available as a GUI application for MacOSX, Linux and Windows and as an Android app (KeePassDroid), making it useful to manage passwords across multiple devices.

Features

  • View details: list groups and entries, get details for a single entry
  • Add new entries and change passwords from the commandline
  • Resolve conflicts: users may choose to keep their KeePassX database in a central location such as Dropbox or other synchronisation software. This results in "conflicting copies" being generated if a opens and updates the database from more than one device. kpcli avoids these conflicts, and also provides a utility to compare conflicting copies and identify where the conflicts lie.

Installation

Using pip:

pip install kpcli

From source:

git clone https://github.com/rebkwok/kpcli.git
cd kpcli
poetry install  # pip install poetry first if necessary

Configuration

kpcli will look for database configuration first in in environment variables, and then in a config.ini file.

The (encrypted) database password can be stored by setting STORE_ENCRYPTED_PASSWORD to True in the config.ini file or as an environment variable. kpcli will prompt for the password once and then every 24 hours.

NOTE: AT YOUR OWN RISK! KEEPASSDB_PASSWORD can be set in plaintext in the config.ini file or as an environment variable if you really want to. If no KEEPASSDB_PASSWORD is found, kpcli will prompt for it.

Config file

Create a config file at $(HOME)/.kp/config.ini, with at least a default profile, and your database location and credentials:

[default]
KEEPASSDB=/Users/me/mypassworddb.kdbx

If your database uses a key file, provide that location too:

[default]
KEEPASSDB=/path/to/mypassworddb.kdbx
KEYPASSDB_KEYFILE=/path/to/mykeyfile.key

More than one profile can be set for multiple databases, and switched with the -p flag

[default]
KEEPASSDB=/path/to/db.kdbx
KEYPASSDB_KEYFILE=/path/to/mykeyfile.key

[work]
KEEPASSDB=/path/to/workdb.kdbx

By default, passwords copied to the clipboard will timeout after 5 seconds. To change the timeout, provide a KEYPASSDB_TIMEOUT config or environment variable.

Environment Variables

If no config.ini file exists, kpcli will attempt to find config in the environment variables KEEPASSDB, KEYPASSDB_KEYFILE and KEEPASSDB_PASSWORD (falling back to a prompt for the password).

For more detailed usage, use --help with any kpcli command listed below.

Usage:

$ kpcli [OPTIONS] COMMAND [ARGS]...

Options:

  • -p, --profile TEXT: Specify config profile to use [default: default]
  • --loglevel TEXT: [default: INFO]
  • --install-completion: Install completion for the current shell.
  • --show-completion: Show completion for the current shell, to copy it or customize the installation.
  • --help: Show this message and exit.

Commands:

Group names and entry titles can be passed as partial, case-insensitive strings for matching.

  • ls: List groups and entries
  • add-group: Add a new group
  • rm-group: delete a group
  • get: Fetch details for a single entry
  • cp: Copy entry attribute to clipboard
  • add: Add a new entry
  • edit: Edit an entry's attributes (except password)
  • change-password: Change entry password
  • rm: Delete an entry
  • compare: Compare potentially conflicting copies of a KeePassX Database and report conflicts

Usage Examples

List groups and entries
$ kpcli ls

Database: /path/to/db.kdbx
================================================================================
Groups
================================================================================
Root
Internet
Communications
...

$ kpcli ls --group comm --entries
Database: /path/to/db.kdbx
================================================================================
Communications
================================================================================
my email
work email
...
List groups in the database from the "work" profile:
$ kpcli --profile work ls
Database: /path/to/workdb.kdbx
================================================================================
Groups
================================================================================
Root
Work
...
Get an entry

By group and entry title, separated with /. Note partial matches are allowed.
If multiple matching entries are found, all will be listed.

$ kpcli get comm/email
Database: /path/to/db.kdbx
================================================================================
Communications/my email
================================================================================
name: Communications/my email
username: my@email.com
password: **********
URL:
Notes: This is my main email address
Copy an attribute (default password) from an entry to the clipboard

If multiple entries match, kpcli prompts for a selection.

$ kpcli cp comm/email
Entry: Communications/my email
password copied to clipboard

$ kpcli cp comm/email username
Entry: Communications/my email
username copied to clipboard
Add an entry
$ kpcli add

kpcli will prompt for required fields.

Change a password
$ kpcli change-password comm/email

kpcli will prompt for new password.

Compare conflicting databases

In the example below, kpcli found one conflicting db to compare.
The entry with title "entry1" in group "blue" is present in the conflicting db, but missing in the main db.
Entry blue/entry2 is present in the main db but missing in the conflicting db.
Entry red/entry3 is present in both dbs, but has conflicting username and password values.

$ kpcli compare

Database: path/to/db.kdbx
Database password:
Looking for conflicting files...
================================================================================
Comparison db: path/to/db_conflicting_copy.kdbx
================================================================================
╔════════════╤═════════════╤════════════════════╗
║ Main       │ Conflicting │ Conflicting fields ║
╠════════════╪═════════════╪════════════════════╣
║ -          │ blue/entry1 │                    ║ 
╟────────────┼─────────────┼────────────────────╢
║ blue/entry2│ -           │                    ║
╟────────────┼─────────────┼────────────────────╢
║ red/entry3 │ red/entry3  │ username, password ║
╚════════════╧═════════════╧════════════════════╝

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kpcli-0.2.2.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

kpcli-0.2.2-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

Details for the file kpcli-0.2.2.tar.gz.

File metadata

  • Download URL: kpcli-0.2.2.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.0 Darwin/18.0.0

File hashes

Hashes for kpcli-0.2.2.tar.gz
Algorithm Hash digest
SHA256 db8744d65ce25c0b73b397c33de71d24895eef659e0e0c2bf34799f54b7513b4
MD5 ee7bfad4f2269a2648b422c3529a1d5c
BLAKE2b-256 ebf84119481463805f3fbb8cfbcdd590556821a9ab3c4f8a9291635aba28960c

See more details on using hashes here.

File details

Details for the file kpcli-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: kpcli-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 26.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.0 Darwin/18.0.0

File hashes

Hashes for kpcli-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c167e737dfa74db8ef70085426b0d4848e1015ee6a2d8441de3f0ad40b1da850
MD5 267af3af7456ba5167e91fb6ecb7c2e1
BLAKE2b-256 4f7295a7d71225b05fb840dc16f3e4657f469cce7233416c01c4cdd2fe7753d8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page