Cheatsheets:Keepassxc-cli: Difference between revisions
No edit summary |
Rewrite the command sections in REPL form, add option tables for add/edit, generate, ls, show; fix the Search lead-in that rendered as preformatted text and a few typos. Implemented the HTML-comment advice (comments now removed). AI-assisted (RonzzWikiCowriter) (via update-page on MediaWiki MCP Server) |
||
| Line 1: | Line 1: | ||
{{DesktopLinux}} | {{DesktopLinux}} | ||
<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 | <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 as the desktop application, to manage your secrets from a terminal. | ||
New to it? | New to it? | ||
| Line 11: | Line 11: | ||
== DB ops == | == DB ops == | ||
KeePassXC | KeePassXC stores all your secrets in encrypted <code>.kdbx</code> files. | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
| Line 33: | Line 33: | ||
== Keepassxc-cli repl == | == Keepassxc-cli repl == | ||
Once the <code>.kdbx</code> is set up, | 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 Passwords.kdbx | keepassxc-cli open Passwords.kdbx # enter a repl on Passwords.kdbx; the prompt is the database name | ||
keepassxc-cli -k keyfile open Passwords.kdbx # if a key file is also required | keepassxc-cli -k keyfile open Passwords.kdbx # ...if a key file is also required | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 45: | Line 45: | ||
Passwords> clip -t Internet/site1 | Passwords> clip -t Internet/site1 | ||
Passwords> close # close the current database, stay in the repl | Passwords> close # close the current database, stay in the repl | ||
Passwords> exit # | Passwords> exit # exit the repl | ||
</pre> | </pre> | ||
<blockquote> | <blockquote> | ||
<code>export</code> and <code>import</code> do not work in repl | <code>export</code> and <code>import</code> do not work in the repl. | ||
Every other command works in both forms: <code>Passwords> ls</code> inside the repl, <code>keepassxc-cli ls Passwords.kdbx</code> outside it, the database being then the first argument. The sections below use the repl form. | |||
</blockquote> | </blockquote> | ||
== Edit secrets == | == Edit secrets == | ||
'''add''' creates an entry, '''edit''' changes one, '''rm''' deletes it, and '''mkdir''', '''mv''' and '''rmdir''' organise the groups: | |||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
Passwords> add -u user1 -g Internet/site3 # -g: generate the password | |||
Passwords> add -u user1 -p Internet/site3 # -p: prompt for the password | |||
Passwords> add -u user1 -g -L 24 -s Internet/site3 # generated: 24 characters, special ones included | |||
Passwords> add -u user1 -g --url https://example.com Internet/site3 | |||
Passwords> edit -u user2 Internet/site3 # change one field | |||
Passwords> edit -t Mail Internet/site3 # rename the entry | |||
Passwords> edit -g Internet/site3 # replace the password with a generated one | |||
Passwords> rm Internet/site3 # delete: to the recycle bin, when one is enabled | |||
Passwords> mkdir Internet/Sub # new group; parent groups must exist | |||
Passwords> mv Internet/site3 Work # move an entry to another group | |||
Passwords> rmdir Work # remove a group | |||
</syntaxhighlight> | </syntaxhighlight> | ||
< | <code>add</code> and <code>edit</code> take the same options, except <code>-t</code>: | ||
{| class="wikitable" | |||
! Option !! Effect | |||
|- | |||
| <code>-u NAME</code>, <code>--username</code> || set the username | |||
</ | |- | ||
| <code>--url URL</code> || set the URL | |||
|- | |||
| <code>--notes TEXT</code> || set the notes; <code>\n</code> becomes a line break | |||
|- | |||
| <code>-p</code>, <code>--password-prompt</code> || ask for the entry's password | |||
|- | |||
| <code>-g</code>, <code>--generate</code> || generate the entry's password (see [[#Generate passwords|the generator options]]) | |||
|- | |||
| <code>-t TITLE</code>, <code>--title</code> || rename the entry — <code>edit</code> only | |||
|} | |||
< | <blockquote> | ||
<code>edit</code> refuses to run without at least one field option: <code>Not changing any field for entry Internet/site3.</code> | |||
</blockquote> | |||
</ | |||
<blockquote> | <blockquote> | ||
<code>-p</code> | <code>-p</code> reads the entry's password from <code>stdin</code>, like the master password does. As a one-off command outside the repl, the two lines come in order — master password, then the entry's: | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
printf 'masterpass\nnewpass\n' | keepassxc-cli -q add -p -u user1 db.kdbx Internet/site3 | printf 'masterpass\nnewpass\n' | keepassxc-cli -q add -p -u user1 db.kdbx Internet/site3 | ||
| Line 88: | Line 105: | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
Passwords> generate # 16 characters: lowercase, uppercase, digits | |||
Passwords> generate -L 24 -s # 24 characters, special ones included | |||
Passwords> generate -L 20 --exclude-similar # avoid look-alikes such as l, 1 and I | |||
Passwords> generate -x 'a,b,c' # exclude individual characters | |||
Passwords> generate -c 'abcdef1234' # only from these characters | |||
Passwords> generate --every-group # at least one character from every selected group | |||
</syntaxhighlight> | |||
The same options apply to <code>generate</code>, to <code>add -g</code> and to <code>edit -g</code>: | |||
{| class="wikitable" | |||
! Option !! Effect | |||
|- | |||
| <code>-L N</code>, <code>--length</code> || length of the password, 16 by default | |||
|- | |||
| <code>-l</code>, <code>--lower</code> || lowercase letters (enabled by default) | |||
|- | |||
| <code>-U</code>, <code>--upper</code> || uppercase letters (enabled by default) | |||
|- | |||
| <code>-n</code>, <code>--numeric</code> || digits (enabled by default) | |||
|- | |||
| <code>-s</code>, <code>--special</code> || special characters (disabled by default) | |||
|- | |||
| <code>-e</code>, <code>--extended</code> || extended ASCII characters (disabled by default) | |||
|- | |||
| <code>-x CHARS</code>, <code>--exclude</code> || exclude these characters, comma-separated | |||
|- | |||
| <code>-c CHARS</code>, <code>--custom</code> || draw from these characters only | |||
|- | |||
| <code>--exclude-similar</code> || drop look-alikes such as <code>l</code>, <code>1</code> and <code>I</code> | |||
|- | |||
| <code>--every-group</code> || at least one character from every selected class | |||
|} | |||
'''diceware''' — passphrases: | |||
<syntaxhighlight lang="bash" copy> | |||
Passwords> diceware # 7 words | |||
Passwords> diceware -W 5 # 5 words | |||
Passwords> diceware -w wordlist.txt # custom word list | |||
</syntaxhighlight> | </syntaxhighlight> | ||
< | {| class="wikitable" | ||
! Option !! Effect | |||
|- | |||
| <code>-W N</code>, <code>--words</code> || number of words, 7 by default | |||
|- | |||
| <code>-w FILE</code>, <code>--word-list</code> || custom word list: more than 1000 words are required, and a warning is printed below 4000 | |||
|} | |||
'''estimate''' — entropy of a password: | |||
<syntaxhighlight lang="bash" copy> | |||
Passwords> estimate 'some_password' # entropy of a given password | |||
Passwords> estimate -a 'some_password' # -a: advanced analysis | |||
</syntaxhighlight> | |||
== List == | == List == | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
Passwords> ls # root group: entries, then sub-groups | |||
Passwords> ls Internet # one group | |||
Passwords> ls -R # recurse into every group | |||
Passwords> ls -f -R # one full path per line | |||
</syntaxhighlight> | </syntaxhighlight> | ||
< | {| class="wikitable" | ||
! Option !! Effect | |||
|- | |||
| <code>-R</code>, <code>--recursive</code> || list the contents of the sub-groups too | |||
|- | |||
| <code>-f</code>, <code>--flatten</code> || print <code>group-path/title</code> on one line per entry, instead of an indented tree | |||
|} | |||
== Search == | == Search == | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
Passwords> search site # entries matching a term | |||
Passwords> search 'title:mail' # field-qualified term | |||
Passwords> search 'has:totp' # every entry with TOTP set up | |||
</syntaxhighlight> | </syntaxhighlight> | ||
'''search''' — the same query language as in the GUI search box: | |||
{| class="wikitable" | {| class="wikitable" | ||
| Line 144: | Line 208: | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
Passwords> show site1 # default fields; the password reads PROTECTED | |||
Passwords> show -s Internet/site1 # -s: reveal protected values too | |||
Passwords> show -a username -a password Internet/site1 # specific attributes, one per line | |||
</syntaxhighlight> | </syntaxhighlight> | ||
< | {| class="wikitable" | ||
! Option !! Effect | |||
|- | |||
| <code>-a ATTR</code>, <code>--attributes</code> || print the named attribute, without its field label; repeat the flag for several, printed one per line | |||
|- | |||
| <code>-s</code>, <code>--show-protected</code> || reveal protected values in clear text | |||
|- | |||
| <code>--all</code> || every attribute, custom ones included | |||
|- | |||
| <code>--show-attachments</code> || attachment names and sizes | |||
|- | |||
| <code>-t</code>, <code>--totp</code> || the current TOTP code (see [[#TOTP]]) | |||
|} | |||
Naming the attribute is what makes the output script-friendly: | Naming the attribute is what makes the output script-friendly: | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
PASSWORD="$(keepassxc-cli -q show -a password | PASSWORD="$(keepassxc-cli -q show -a password Passwords.kdbx Internet/site1)" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 166: | Line 241: | ||
== Clip: Copy to the clipboard == | == Clip: Copy to the clipboard == | ||
Replace <code>show</code> with <code>clip</code> to copy to clipboard instead of printing to <code> | Replace <code>show</code> with <code>clip</code> to copy to the clipboard instead of printing to <code>stdout</code>. | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
Passwords> clip site1 # copy the password; the clipboard is cleared after 10 s | |||
Passwords> clip -a username site1 # copy any attribute of the entry: username, url, notes, ... | |||
Passwords> clip -t site1 # copy the current TOTP code to the clipboard | |||
Passwords> clip site1 30 # clear after 30 s instead; 0 keeps it until it is overwritten | |||
Passwords> clip -b github # unique title match only, no group path needed | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 181: | Line 258: | ||
<blockquote> | <blockquote> | ||
'''Caveat''': <code>keepassxc-cli</code> currently only supports generating TOTP from an entry already | '''Caveat''': <code>keepassxc-cli</code> currently only supports generating a TOTP from an entry already set up. The setup must be done in the GUI. | ||
</blockquote> | </blockquote> | ||
<syntaxhighlight lang="bash" copy> | <syntaxhighlight lang="bash" copy> | ||
Passwords> show -t site1 # show the current code | |||
OTP="$(keepassxc-cli -q show -t | Passwords> show -a password -t Internet/site1 # ...alongside other fields | ||
Passwords> clip -t site1 # copy the code to the clipboard | |||
Passwords> show -a otp site1 # the stored otpauth:// secret, to enrol another device | |||
OTP="$(keepassxc-cli -q show -t Passwords.kdbx site1)" # code only, outside the repl, for a scripted login | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 204: | Line 283: | ||
|- | |- | ||
| <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> | ||
|- | |||
| <code>Not changing any field for entry X.</code> || <code>edit</code> was given no field option: pass at least one, e.g. <code>edit -u user2 Internet/site3</code> | |||
|- | |||
| the command waits for input in a script || the master password is read from <code>stdin</code>: pipe it, or unlock with <code>-k keyfile</code> | |||
|} | |} | ||
Revision as of 09:54, 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 as the desktop application, to manage your secrets from a terminal.
New to it?
keepassxc-cli helplists every commandkeepassxc-cli <command> -hdocuments one commandman keepassxc-cliprovides a full reference
DB ops
KeePassXC stores 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 repl on Passwords.kdbx; 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 # exit the repl
exportandimportdo not work in the repl.Every other command works in both forms:
Passwords> lsinside the repl,keepassxc-cli ls Passwords.kdbxoutside it, the database being then the first argument. The sections below use the repl form.
Edit secrets
add creates an entry, edit changes one, rm deletes it, and mkdir, mv and rmdir organise the groups:
Passwords> add -u user1 -g Internet/site3 # -g: generate the password
Passwords> add -u user1 -p Internet/site3 # -p: prompt for the password
Passwords> add -u user1 -g -L 24 -s Internet/site3 # generated: 24 characters, special ones included
Passwords> add -u user1 -g --url https://example.com Internet/site3
Passwords> edit -u user2 Internet/site3 # change one field
Passwords> edit -t Mail Internet/site3 # rename the entry
Passwords> edit -g Internet/site3 # replace the password with a generated one
Passwords> rm Internet/site3 # delete: to the recycle bin, when one is enabled
Passwords> mkdir Internet/Sub # new group; parent groups must exist
Passwords> mv Internet/site3 Work # move an entry to another group
Passwords> rmdir Work # remove a group
add and edit take the same options, except -t:
| Option | Effect |
|---|---|
-u NAME, --username |
set the username |
--url URL |
set the URL |
--notes TEXT |
set the notes; \n becomes a line break
|
-p, --password-prompt |
ask for the entry's password |
-g, --generate |
generate the entry's password (see the generator options) |
-t TITLE, --title |
rename the entry — edit only
|
editrefuses to run without at least one field option:Not changing any field for entry Internet/site3.
-preads the entry's password fromstdin, like the master password does. As a one-off command outside the repl, the two lines come 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
Passwords> generate # 16 characters: lowercase, uppercase, digits
Passwords> generate -L 24 -s # 24 characters, special ones included
Passwords> generate -L 20 --exclude-similar # avoid look-alikes such as l, 1 and I
Passwords> generate -x 'a,b,c' # exclude individual characters
Passwords> generate -c 'abcdef1234' # only from these characters
Passwords> generate --every-group # at least one character from every selected group
The same options apply to generate, to add -g and to edit -g:
| Option | Effect |
|---|---|
-L N, --length |
length of the password, 16 by default |
-l, --lower |
lowercase letters (enabled by default) |
-U, --upper |
uppercase letters (enabled by default) |
-n, --numeric |
digits (enabled by default) |
-s, --special |
special characters (disabled by default) |
-e, --extended |
extended ASCII characters (disabled by default) |
-x CHARS, --exclude |
exclude these characters, comma-separated |
-c CHARS, --custom |
draw from these characters only |
--exclude-similar |
drop look-alikes such as l, 1 and I
|
--every-group |
at least one character from every selected class |
diceware — passphrases:
Passwords> diceware # 7 words
Passwords> diceware -W 5 # 5 words
Passwords> diceware -w wordlist.txt # custom word list
| Option | Effect |
|---|---|
-W N, --words |
number of words, 7 by default |
-w FILE, --word-list |
custom word list: more than 1000 words are required, and a warning is printed below 4000 |
estimate — entropy of a password:
Passwords> estimate 'some_password' # entropy of a given password
Passwords> estimate -a 'some_password' # -a: advanced analysis
List
Passwords> ls # root group: entries, then sub-groups
Passwords> ls Internet # one group
Passwords> ls -R # recurse into every group
Passwords> ls -f -R # one full path per line
| Option | Effect |
|---|---|
-R, --recursive |
list the contents of the sub-groups too |
-f, --flatten |
print group-path/title on one line per entry, instead of an indented tree
|
Search
Passwords> search site # entries matching a term
Passwords> search 'title:mail' # field-qualified term
Passwords> search 'has:totp' # every entry with TOTP set up
search — 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
Passwords> show site1 # default fields; the password reads PROTECTED
Passwords> show -s Internet/site1 # -s: reveal protected values too
Passwords> show -a username -a password Internet/site1 # specific attributes, one per line
| Option | Effect |
|---|---|
-a ATTR, --attributes |
print the named attribute, without its field label; repeat the flag for several, printed one per line |
-s, --show-protected |
reveal protected values in clear text |
--all |
every attribute, custom ones included |
--show-attachments |
attachment names and sizes |
-t, --totp |
the current TOTP code (see #TOTP) |
Naming the attribute is what makes the output script-friendly:
PASSWORD="$(keepassxc-cli -q show -a password Passwords.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 the clipboard instead of printing to stdout.
Passwords> clip site1 # copy the password; the clipboard is cleared after 10 s
Passwords> clip -a username site1 # copy any attribute of the entry: username, url, notes, ...
Passwords> clip -t site1 # copy the current TOTP code to the clipboard
Passwords> clip site1 30 # clear after 30 s instead; 0 keeps it until it is overwritten
Passwords> clip -b github # unique title match only, no group path needed
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 a TOTP from an entry already set up. The setup must be done in the GUI.
Passwords> show -t site1 # show the current code
Passwords> show -a password -t Internet/site1 # ...alongside other fields
Passwords> clip -t site1 # copy the code to the clipboard
Passwords> show -a otp site1 # the stored otpauth:// secret, to enrol another device
OTP="$(keepassxc-cli -q show -t Passwords.kdbx site1)" # code only, outside the repl, for a scripted login
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
|
Not changing any field for entry X. |
edit was given no field option: pass at least one, e.g. edit -u user2 Internet/site3
|
| the command waits for input in a script | the master password is read from stdin: pipe it, or unlock with -k keyfile
|
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