Cheatsheets:Keepassxc-cli: Difference between revisions

From Wikibase
Jump to navigation Jump to search
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 opens, reads and edits the same encrypted <code>.kdbx</code> databases as the desktop application, so an entry added from a terminal shows up in the GUI and vice versa.
<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? <code>keepassxc-cli help</code> lists every command, <code>keepassxc-cli &lt;command&gt; -h</code> documents one command, and <code>man keepassxc-cli</code> is the full reference.
New to it?  


== Unlocking the database ==
* <code>keepassxc-cli help</code> lists every command
* <code>keepassxc-cli &lt;command&gt; -h</code> documents one command
* <code>man keepassxc-cli</code> provides a full reference


Commands that act on a database take its path as the first argument, then ask for the master password:
== DB ops ==


<syntaxhighlight lang="bash" copy>
KeePassXC store all your secrets in encrypted <code>.kdbx</code> files.
keepassxc-cli ls db.kdbx                            # prompts: Enter password to unlock db.kdbx
keepassxc-cli -k keyfile ls db.kdbx                # also unlock with a key file
keepassxc-cli -k keyfile --no-password ls db.kdbx   # database protected by a key file only
</syntaxhighlight>
 
The password is read from <code>stdin</code>: typed at the terminal (without echo), or piped by a script:


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
echo "$MASTER" | keepassxc-cli ls db.kdbx     # password on stdin, prompts go to stderr
keepassxc-cli db-create -p db.kdbx                        # create a new database
echo "$MASTER" | keepassxc-cli -q ls db.kdbx   # -q: silence the prompt and secondary messages
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>
'''Put global options before the command name:''' <syntaxhighlight lang="bash" inline>keepassxc-cli -q show db.kdbx site1</syntaxhighlight>, <syntaxhighlight lang="bash" inline>keepassxc-cli -k keyfile show db.kdbx site1</syntaxhighlight>, <syntaxhighlight lang="bash" inline>keepassxc-cli -y 1:7370001 show db.kdbx site1</syntaxhighlight> (YubiKey slot, optional serial).
Any file created by <code>export</code> should be considered '''extremely sensitive''', as it contains all your secrets in clear text.
</blockquote>


<blockquote>
<code>import</code> currently only accepts a <code>.xml</code> file previously exported by KeePassXC.
'''Piping the master password leaks it''' into the shell history and the process list. Prefer a key file, or the interactive shell below.
</blockquote>
</blockquote>


== Interactive shell ==
== Keepassxc-cli repl ==


Unlock once, then run as many commands as you like without retyping the master password:
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 db.kdbx      # shell-style session, the prompt is the database name
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&gt; show -s Internet/site1
Passwords&gt; show -s Internet/site1
Passwords&gt; clip -t Internet/site1
Passwords&gt; clip -t Internet/site1
Passwords&gt; close                  # close the current database, stay in the shell
Passwords&gt; close                  # close the current database, stay in the repl
Passwords&gt; quit                   # or exit
Passwords&gt; exit                   # exist repl
</pre>
</pre>


<blockquote>
<blockquote>
<code>export</code> and <code>import</code> exist only outside the shell; <code>close</code>, <code>exit</code> and <code>quit</code> only inside it.
<code>export</code> and <code>import</code> do not work in repl
</blockquote>
</blockquote>


== List and search ==
<!-- all following sections should be rewritten as commands inside the repl when possible: e.g., keepassxc-cli ls db.kdbx becomes Passwords&gt; 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>


<pre>
the same query language as in the GUI search box:
$ keepassxc-cli ls db.kdbx
site0
Internet/
  site1
  site2
Work/
  [empty]
 
$ keepassxc-cli search db.kdbx site
/Internet/site1
/Work/site3
</pre>
 
Sub-groups are printed with a trailing <code>/</code>, indented by two spaces per level; an empty group shows <code>[empty]</code>. Commands accept both <code>Internet/site1</code> and <code>/Internet/site1</code>.
 
'''search''' — the same query language as 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> or <code>!term</code> || excludes the term
| <code>!term</code> || excludes the term
|-
|-
| <code>+term</code> || the term exactly, not as a substring
| <code>+term</code> || exact term only, not as a substring
|-
|-
| <code>a&#124;b</code> || either term
| <code>a&#124;b</code> || either term
Line 99: Line 144:


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli show db.kdbx site1                    # title, username, URL, notes; password reads PROTECTED
keepassxc-cli show db.kdbx site1                    # -s: reveal protected values too
keepassxc-cli show -s 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 db.kdbx site1        # value only, no field label
keepassxc-cli show -a username -a password db.kdbx Internet/site1  # several attributes, one per line
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 is addressed by its title alone when that title is unique in the database, otherwise by group path and title. <code>ls -f -R</code> prints every valid path.
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>


<blockquote>
== Clip: Copy to the clipboard ==
'''<code>-s</code>, <code>-a password</code> and <code>--all</code> print secrets in clear text:''' they stay in the terminal scrollback, and in the shell history when typed on a command line.
</blockquote>


== 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, clipboard cleared after 10 s
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 30           # clear after 30 s instead; 0 keeps it until overwritten
keepassxc-cli clip -t db.kdbx site1            # copy current totp code to system clipboard
keepassxc-cli clip -b github                  # unique title match only, no group path needed
</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 ==
<syntaxhighlight lang="bash" copy>
keepassxc-cli show -t db.kdbx site1                        # the current code, and nothing else
keepassxc-cli show -a username -a password -t db.kdbx site1 # ...or after the other fields
keepassxc-cli clip -t db.kdbx site1                        # copy the code to the clipboard
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
</syntaxhighlight>


<blockquote>
<blockquote>
The code is computed locally from the secret stored in the entry: 6 digits, renewed every 30 seconds by default. No network access is needed, but a drifting system clock makes the server reject the codes.
'''Caveat''': <code>keepassxc-cli</code> currently only supports generating TOTP from an entry already setup. The setup must be done in GUI.
</blockquote>
</blockquote>
<blockquote>
The entry must have TOTP configured first (in the GUI: right-click the entry → TOTP → Set up TOTP…), or the command fails with <code>Entry with path site1 has no TOTP set up.</code>
</blockquote>
<blockquote>
'''TOTP stored beside the password is one factor, not two:''' whoever unlocks the database gets both. Keep TOTP codes in a separate database when the second factor has to stay independent.
</blockquote>
== Add, edit, remove ==


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli add -u user1 -g db.kdbx Internet/site3          # -g: generate the password
keepassxc-cli show -t db.kdbx site1                        # show the current code
keepassxc-cli add -u user1 -p db.kdbx Internet/site3          # -p: prompt for the password
OTP="$(keepassxc-cli -q show -t db.kdbx site1)"            # code only, for a scripted login
keepassxc-cli add -u user1 -g -L 24 -s db.kdbx Internet/site3  # generated: 24 characters, special ones included
keepassxc-cli show -a otp db.kdbx site1                    # the stored otpauth:// secret, to enrol another device
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>
</syntaxhighlight>


<blockquote>
<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:
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.
<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>
 
== Database operations ==
 
<syntaxhighlight lang="bash" copy>
keepassxc-cli db-create -p db.kdbx                        # new database; prompts twice for its password
keepassxc-cli db-create -p --set-key-file keyfile db.kdbx  # password and key file as two factors
keepassxc-cli db-info db.kdbx                              # entries, groups, encryption parameters
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            # drop the password factor, keep another one
keepassxc-cli export -f csv db.kdbx > export.csv          # every secret, in clear text
keepassxc-cli import export.xml new.kdbx                  # import into a new database
</syntaxhighlight>
 
<blockquote>
'''<code>export</code> writes every password in clear text''' — mind where the file lands, and delete it once the import is done.
</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>Entry with path X has no TOTP set up.</code> || TOTP was never configured on that entry: set it up in the GUI first
|-
|-
| <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>
|-
| 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:52, 30 September 2026

Languages: English · français · Esperanto

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 help lists every command
  • keepassxc-cli <command> -h documents one command
  • man keepassxc-cli provides 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 export should be considered extremely sensitive, as it contains all your secrets in clear text.

import currently only accepts a .xml file 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

export and import do 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

-p prompts for the entry's password, but like the master password it only reads stdin: 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


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 title alone when that title is unique, otherwise it must be addressed by group-path/title.

ls -f -R prints 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, clip pipes to wl-copy (Wayland) or xclip (X11); without either one it fails with error All clipping programs failed.

TOTP

Caveat: keepassxc-cli currently 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 help and man keepassxc-cli — the same reference, offline
  • analyze — offline Have I Been Pwned check against a downloaded password-hash list
  • merge — merge two databases into one
  • attachment-import, attachment-export, attachment-rm — manage file attachments
  • Cheatsheets:LinuxCLI/ssh — SSH keys and ssh-agent, which KeePassXC can feed