Cheatsheets:Keepassxc-cli: Difference between revisions
New cheatsheet: basic keepassxc-cli operations, including TOTP. AI-assisted (RonzzWikiCowriter) (via create-page on MediaWiki MCP Server) |
No edit summary |
||
| Line 1: | Line 1: | ||
{{DesktopLinux}} | {{DesktopLinux}} | ||
<code>keepassxc-cli</code> is the command-line client of [[FOSS:KeePassXC|KeePassXC]]: it | <code>keepassxc-cli</code> is the command-line client of [[FOSS:KeePassXC|KeePassXC]]: it can open, read and edit the same encrypted <code>.kdbx</code> databases just like the desktop application to manage your secrets | ||
New to it? | New to it? | ||
* <code>keepassxc-cli help</code> lists every command | |||
* <code>keepassxc-cli <command> -h</code> documents one command | |||
* <code>man keepassxc-cli</code> provides a full reference | |||
== DB ops == | |||
< | KeePassXC store all your secrets in encrypted <code>.kdbx</code> files. | ||
</ | |||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
keepassxc-cli db-create -p db.kdbx # create a new database | |||
keepassxc-cli db-create --set-key-file keyfile db.kdbx # create a new database protected by a key file | |||
keepassxc-cli db-info db.kdbx # show info on a .kdbx DB | |||
keepassxc-cli db-edit -p db.kdbx # change the master password | |||
keepassxc-cli db-edit --set-key-file keyfile db.kdbx # add or replace the key file | |||
keepassxc-cli db-edit --unset-password db.kdbx # remove the password encryption | |||
keepassxc-cli export -f csv db.kdbx > export.csv # export every secret to csv in clear text | |||
keepassxc-cli export -f xml db.kdbx > export.xml # export every secret to xml to be reimported into another .kdbx | |||
keepassxc-cli import export.xml new.kdbx # import from a previously exported .xml into a new database | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<blockquote> | <blockquote> | ||
''' | Any file created by <code>export</code> should be considered '''extremely sensitive''', as it contains all your secrets in clear text. | ||
< | <code>import</code> currently only accepts a <code>.xml</code> file previously exported by KeePassXC. | ||
</blockquote> | </blockquote> | ||
== | == Keepassxc-cli repl == | ||
Once the <code>.kdbx</code> is set up, The first step to interact with it is almost always to enter the command repl on a particular <code>.kdbx</code> database, otherwise you have to retype the master password for every single command. | |||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
keepassxc-cli open | keepassxc-cli open Passwords.kdbx # enter a keepassxc-cli repl on Passwords.kdbx shell-style session, the prompt is the database name | ||
keepassxc-cli -k keyfile open Passwords.kdbx # if a key file is also required | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 42: | Line 44: | ||
Passwords> show -s Internet/site1 | Passwords> show -s Internet/site1 | ||
Passwords> clip -t Internet/site1 | Passwords> clip -t Internet/site1 | ||
Passwords> close # close the current database, stay in the | Passwords> close # close the current database, stay in the repl | ||
Passwords> | Passwords> exit # exist repl | ||
</pre> | </pre> | ||
<blockquote> | <blockquote> | ||
<code>export</code> and <code>import</code> | <code>export</code> and <code>import</code> do not work in repl | ||
</blockquote> | </blockquote> | ||
== List | <!-- all following sections should be rewritten as commands inside the repl when possible: e.g., keepassxc-cli ls db.kdbx becomes Passwords> ls--> | ||
== Edit secrets == | |||
<!-- use option tables in this section, as the command structures and options for add/edit are extremely similar--> | |||
<syntaxhighlight lang="bash" copy> | |||
keepassxc-cli add -u user1 -g db.kdbx Internet/site3 # -g: generate the password | |||
keepassxc-cli add -u user1 -p db.kdbx Internet/site3 # -p: prompt for the password | |||
keepassxc-cli add -u user1 -g -L 24 -s db.kdbx Internet/site3 # generated: 24 characters, special ones included | |||
keepassxc-cli add -u user1 -g --url https://example.com db.kdbx Internet/site3 | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" copy> | |||
keepassxc-cli edit -u user2 db.kdbx Internet/site3 # change one field | |||
keepassxc-cli edit -t Mail db.kdbx Internet/site3 # rename (-t is --title here, not TOTP) | |||
keepassxc-cli edit -g db.kdbx Internet/site3 # replace the password with a generated one | |||
keepassxc-cli edit -p db.kdbx Internet/site3 # ...or type a new one | |||
keepassxc-cli rm db.kdbx Internet/site3 # delete: to the recycle bin, when one is enabled | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" copy> | |||
keepassxc-cli mkdir db.kdbx Internet/Sub # new group; parent groups must exist | |||
keepassxc-cli mv db.kdbx Internet/site3 Work # move an entry to another group | |||
keepassxc-cli rmdir db.kdbx Work # remove a group | |||
</syntaxhighlight> | |||
<blockquote> | |||
<code>-p</code> prompts for the entry's password, but like the master password it only reads <code>stdin</code>: two lines, in order — master password, then the entry's: | |||
<syntaxhighlight lang="bash" copy> | |||
printf 'masterpass\nnewpass\n' | keepassxc-cli -q add -p -u user1 db.kdbx Internet/site3 | |||
</syntaxhighlight> | |||
</blockquote> | |||
== Generate passwords == | |||
<syntaxhighlight lang="bash" copy> | |||
keepassxc-cli generate # 16 characters: lowercase, uppercase, digits | |||
keepassxc-cli generate -L 24 -s # 24 characters, special ones included | |||
keepassxc-cli generate -L 20 --exclude-similar # avoid look-alikes such as l, 1 and I | |||
keepassxc-cli generate -x 'a,b,c' # exclude individual characters | |||
keepassxc-cli generate -c 'abcdef1234' # only from these characters | |||
keepassxc-cli generate -e # add extended ASCII | |||
keepassxc-cli generate --every-group # at least one character from every selected group | |||
keepassxc-cli diceware # 7-word passphrase | |||
keepassxc-cli diceware -W 5 # 5 words | |||
keepassxc-cli diceware -w wordlist.txt # custom word list | |||
keepassxc-cli estimate 'some_password' # entropy of a given password | |||
keepassxc-cli estimate -a 'some_password' # ...with advanced analysis | |||
</syntaxhighlight> | |||
<!-- use option tables in this section, as the command structures/behaviour are extremely similar --> | |||
== List == | |||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
| Line 57: | Line 111: | ||
keepassxc-cli ls -R db.kdbx # recurse into every group | keepassxc-cli ls -R db.kdbx # recurse into every group | ||
keepassxc-cli ls -f -R db.kdbx # -f: flatten, one full path per line | keepassxc-cli ls -f -R db.kdbx # -f: flatten, one full path per line | ||
</syntaxhighlight> | |||
<!-- use an options table instead for ls -f and -R--> | |||
== Search == | |||
<syntaxhighlight lang="bash" copy> | |||
keepassxc-cli search db.kdbx site # entries matching a term | keepassxc-cli search db.kdbx site # entries matching a term | ||
keepassxc-cli search db.kdbx 'title:mail' # field-qualified term | keepassxc-cli search db.kdbx 'title:mail' # field-qualified term | ||
| Line 62: | Line 123: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
the same query language as in the GUI search box: | |||
{| class="wikitable" | {| class="wikitable" | ||
| Line 89: | Line 134: | ||
| <code>is:weak</code>, <code>is:expired</code> || weak or expired passwords | | <code>is:weak</code>, <code>is:expired</code> || weak or expired passwords | ||
|- | |- | ||
| | | <code>!term</code> || excludes the term | ||
|- | |- | ||
| <code>+term</code> || | | <code>+term</code> || exact term only, not as a substring | ||
|- | |- | ||
| <code>a|b</code> || either term | | <code>a|b</code> || either term | ||
| Line 99: | Line 144: | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
keepassxc-cli show db.kdbx site1 | keepassxc-cli show db.kdbx site1 # -s: reveal protected values too | ||
keepassxc-cli show -a username -a password db.kdbx Internet/site1 # show specific attributes, one per line | |||
keepassxc-cli show -a username -a password db.kdbx Internet/site1 # | |||
keepassxc-cli show --all db.kdbx site1 # every attribute, custom ones included | keepassxc-cli show --all db.kdbx site1 # every attribute, custom ones included | ||
keepassxc-cli show --show-attachments db.kdbx site1 # attachment names and sizes | keepassxc-cli show --show-attachments db.kdbx site1 # attachment names and sizes | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<!-- use an options table instead for --all, --show-attachments --> | |||
Naming the attribute is what makes the output script-friendly: | Naming the attribute is what makes the output script-friendly: | ||
| Line 114: | Line 159: | ||
<blockquote> | <blockquote> | ||
An entry | An entry can be addressed by <code>title</code> alone when that title is unique, otherwise it must be addressed by <code>group-path/title</code>. | ||
<code>ls -f -R</code> prints every valid path. | |||
</blockquote> | </blockquote> | ||
== Clip: Copy to the clipboard == | |||
Replace <code>show</code> with <code>clip</code> to copy to clipboard instead of printing to <code>stout</code>. | |||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
keepassxc-cli clip db.kdbx site1 # password | keepassxc-cli clip db.kdbx site1 # copy password of the entry to the clipboard. clipboard will be cleared after 10 s | ||
keepassxc-cli clip -a username db.kdbx site1 # any attribute: username, url, notes, ... | keepassxc-cli clip -a username db.kdbx site1 # copy any attribute of the entry: username, url, notes, ... | ||
keepassxc-cli clip db.kdbx site1 | keepassxc-cli clip -t db.kdbx site1 # copy current totp code to system clipboard | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<blockquote> | <blockquote> | ||
On Linux, <code>clip</code> pipes to <code>wl-copy</code> (Wayland) or <code>xclip</code> (X11); without either one it fails with <code>All clipping programs failed.</code> | On Linux, <code>clip</code> pipes to <code>wl-copy</code> (Wayland) or <code>xclip</code> (X11); without either one it fails with error <code>All clipping programs failed.</code> | ||
</blockquote> | </blockquote> | ||
== TOTP == | == TOTP == | ||
<blockquote> | <blockquote> | ||
'''Caveat''': <code>keepassxc-cli</code> currently only supports generating TOTP from an entry already setup. The setup must be done in GUI. | |||
</blockquote> | </blockquote> | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
keepassxc-cli | keepassxc-cli show -t db.kdbx site1 # show the current code | ||
OTP="$(keepassxc-cli -q show -t db.kdbx site1)" # code only, for a scripted login | |||
keepassxc-cli show -a otp db.kdbx site1 # the stored otpauth:// secret, to enrol another device | |||
keepassxc-cli | |||
keepassxc-cli | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<blockquote> | <blockquote> | ||
The code is computed locally from the secret stored in the entry and the local system clock time. A drifting system clock would generate invalid codes. | |||
</blockquote> | </blockquote> | ||
| Line 226: | Line 200: | ||
|- | |- | ||
| <code>All clipping programs failed.</code> || neither <code>wl-copy</code> nor <code>xclip</code> is installed: install one for <code>clip</code> to work | | <code>All clipping programs failed.</code> || neither <code>wl-copy</code> nor <code>xclip</code> is installed: install one for <code>clip</code> to work | ||
|- | |- | ||
| <code>Could not find entry with path X.</code> || the title is not unique, or the group path is wrong: list the paths with <code>ls -f -R</code> | | <code>Could not find entry with path X.</code> || the title is not unique, or the group path is wrong: list the paths with <code>ls -f -R</code> | ||
|- | |- | ||
| <code>Attribute "X" not found.</code> || wrong attribute name: list them with <code>show --all</code> | | <code>Attribute "X" not found.</code> || wrong attribute name: list them with <code>show --all</code> | ||
|} | |} | ||
Revision as of 09:52, 30 September 2026
Quick reference for smart people — part of our Linux cheatsheets collection.
keepassxc-cli is the command-line client of KeePassXC: it can open, read and edit the same encrypted .kdbx databases just like the desktop application to manage your secrets
New to it?
keepassxc-cli helplists every commandkeepassxc-cli <command> -hdocuments one commandman keepassxc-cliprovides a full reference
DB ops
KeePassXC store all your secrets in encrypted .kdbx files.
keepassxc-cli db-create -p db.kdbx # create a new database
keepassxc-cli db-create --set-key-file keyfile db.kdbx # create a new database protected by a key file
keepassxc-cli db-info db.kdbx # show info on a .kdbx DB
keepassxc-cli db-edit -p db.kdbx # change the master password
keepassxc-cli db-edit --set-key-file keyfile db.kdbx # add or replace the key file
keepassxc-cli db-edit --unset-password db.kdbx # remove the password encryption
keepassxc-cli export -f csv db.kdbx > export.csv # export every secret to csv in clear text
keepassxc-cli export -f xml db.kdbx > export.xml # export every secret to xml to be reimported into another .kdbx
keepassxc-cli import export.xml new.kdbx # import from a previously exported .xml into a new database
Any file created by
exportshould be considered extremely sensitive, as it contains all your secrets in clear text.
importcurrently only accepts a.xmlfile previously exported by KeePassXC.
Keepassxc-cli repl
Once the .kdbx is set up, The first step to interact with it is almost always to enter the command repl on a particular .kdbx database, otherwise you have to retype the master password for every single command.
keepassxc-cli open Passwords.kdbx # enter a keepassxc-cli repl on Passwords.kdbx shell-style session, the prompt is the database name
keepassxc-cli -k keyfile open Passwords.kdbx # if a key file is also required
Passwords> ls Passwords> show -s Internet/site1 Passwords> clip -t Internet/site1 Passwords> close # close the current database, stay in the repl Passwords> exit # exist repl
exportandimportdo not work in repl
Edit secrets
keepassxc-cli add -u user1 -g db.kdbx Internet/site3 # -g: generate the password
keepassxc-cli add -u user1 -p db.kdbx Internet/site3 # -p: prompt for the password
keepassxc-cli add -u user1 -g -L 24 -s db.kdbx Internet/site3 # generated: 24 characters, special ones included
keepassxc-cli add -u user1 -g --url https://example.com db.kdbx Internet/site3
keepassxc-cli edit -u user2 db.kdbx Internet/site3 # change one field
keepassxc-cli edit -t Mail db.kdbx Internet/site3 # rename (-t is --title here, not TOTP)
keepassxc-cli edit -g db.kdbx Internet/site3 # replace the password with a generated one
keepassxc-cli edit -p db.kdbx Internet/site3 # ...or type a new one
keepassxc-cli rm db.kdbx Internet/site3 # delete: to the recycle bin, when one is enabled
keepassxc-cli mkdir db.kdbx Internet/Sub # new group; parent groups must exist
keepassxc-cli mv db.kdbx Internet/site3 Work # move an entry to another group
keepassxc-cli rmdir db.kdbx Work # remove a group
-pprompts for the entry's password, but like the master password it only readsstdin: two lines, in order — master password, then the entry's:printf 'masterpass\nnewpass\n' | keepassxc-cli -q add -p -u user1 db.kdbx Internet/site3
Generate passwords
keepassxc-cli generate # 16 characters: lowercase, uppercase, digits
keepassxc-cli generate -L 24 -s # 24 characters, special ones included
keepassxc-cli generate -L 20 --exclude-similar # avoid look-alikes such as l, 1 and I
keepassxc-cli generate -x 'a,b,c' # exclude individual characters
keepassxc-cli generate -c 'abcdef1234' # only from these characters
keepassxc-cli generate -e # add extended ASCII
keepassxc-cli generate --every-group # at least one character from every selected group
keepassxc-cli diceware # 7-word passphrase
keepassxc-cli diceware -W 5 # 5 words
keepassxc-cli diceware -w wordlist.txt # custom word list
keepassxc-cli estimate 'some_password' # entropy of a given password
keepassxc-cli estimate -a 'some_password' # ...with advanced analysis
List
keepassxc-cli ls db.kdbx # root group: entries, then sub-groups
keepassxc-cli ls db.kdbx Internet # one group
keepassxc-cli ls -R db.kdbx # recurse into every group
keepassxc-cli ls -f -R db.kdbx # -f: flatten, one full path per line
Search
keepassxc-cli search db.kdbx site # entries matching a term
keepassxc-cli search db.kdbx 'title:mail' # field-qualified term
keepassxc-cli search db.kdbx 'has:totp' # every entry with TOTP set up
the same query language as in the GUI search box:
| Syntax | Matches |
|---|---|
title:, username:, url:, notes:, group:, tag: |
one field only; abbreviated forms work (t:, u:, g:, ...)
|
has:totp |
entries with TOTP configured |
is:weak, is:expired |
weak or expired passwords |
!term |
excludes the term |
+term |
exact term only, not as a substring |
a|b |
either term |
Show an entry
keepassxc-cli show db.kdbx site1 # -s: reveal protected values too
keepassxc-cli show -a username -a password db.kdbx Internet/site1 # show specific attributes, one per line
keepassxc-cli show --all db.kdbx site1 # every attribute, custom ones included
keepassxc-cli show --show-attachments db.kdbx site1 # attachment names and sizes
Naming the attribute is what makes the output script-friendly:
PASSWORD="$(keepassxc-cli -q show -a password db.kdbx Internet/site1)"
An entry can be addressed by
titlealone when that title is unique, otherwise it must be addressed bygroup-path/title.
ls -f -Rprints every valid path.
Clip: Copy to the clipboard
Replace show with clip to copy to clipboard instead of printing to stout.
keepassxc-cli clip db.kdbx site1 # copy password of the entry to the clipboard. clipboard will be cleared after 10 s
keepassxc-cli clip -a username db.kdbx site1 # copy any attribute of the entry: username, url, notes, ...
keepassxc-cli clip -t db.kdbx site1 # copy current totp code to system clipboard
On Linux,
clippipes towl-copy(Wayland) orxclip(X11); without either one it fails with errorAll clipping programs failed.
TOTP
Caveat:
keepassxc-clicurrently only supports generating TOTP from an entry already setup. The setup must be done in GUI.
keepassxc-cli show -t db.kdbx site1 # show the current code
OTP="$(keepassxc-cli -q show -t db.kdbx site1)" # code only, for a scripted login
keepassxc-cli show -a otp db.kdbx site1 # the stored otpauth:// secret, to enrol another device
The code is computed locally from the secret stored in the entry and the local system clock time. A drifting system clock would generate invalid codes.
Common errors
| Message | Cause and fix |
|---|---|
All clipping programs failed. |
neither wl-copy nor xclip is installed: install one for clip to work
|
Could not find entry with path X. |
the title is not unique, or the group path is wrong: list the paths with ls -f -R
|
Attribute "X" not found. |
wrong attribute name: list them with show --all
|
For more
- KeePassXC user guide — the official guide: TOTP setup, search syntax, browser and SSH agent integration
- keepassxc-cli(1) man page — every command and every option
keepassxc-cli helpandman keepassxc-cli— the same reference, offlineanalyze— offline Have I Been Pwned check against a downloaded password-hash listmerge— merge two databases into oneattachment-import,attachment-export,attachment-rm— manage file attachments- Cheatsheets:LinuxCLI/ssh — SSH keys and
ssh-agent, which KeePassXC can feed