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)
 
 
(5 intermediate revisions by 2 users not shown)
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 as the desktop application, to manage your secrets from a terminal.


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: <code>db-create, db-info, db-edit, import, export</code> ==


<syntaxhighlight lang="bash" copy>
KeePassXC stores 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 ==
== <code>open</code> DB ==


Unlock once, then run as many commands as you like without retyping the master password:
Once the encrypted <code>.kdbx</code> is set up, <code>open</code> to interact with it.


<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             # will prompt for master password
keepassxc-cli -k keyfile open Passwords.kdbx  # ...if a key file is also required
</syntaxhighlight>
</syntaxhighlight>
This activates a command repl, eliminating the need to retype the master password for each command:


<pre>
<pre>
Line 42: Line 46:
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                   # exit the 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 the repl.
</blockquote>


== List and search ==
Every other command works in both forms:


<syntaxhighlight lang="bash" copy>
* <code>Passwords&gt; [command]</code> inside the repl
keepassxc-cli ls db.kdbx                  # root group: entries, then sub-groups
* <code>keepassxc-cli [command] xxx.kdbx</code> as standalone CLI command
keepassxc-cli ls db.kdbx Internet          # one group
</blockquote>
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
</syntaxhighlight>
 
<pre>
$ 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>.
== Generate passwords/passphrases ==
 
'''search''' — the same query language as the GUI search box:
 
{| class="wikitable"
! Syntax !! Matches
|-
| <code>title:</code>, <code>username:</code>, <code>url:</code>, <code>notes:</code>, <code>group:</code>, <code>tag:</code> || one field only; abbreviated forms work (<code>t:</code>, <code>u:</code>, <code>g:</code>, ...)
|-
| <code>has:totp</code> || entries with TOTP configured
|-
| <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> || the term exactly, not as a substring
|-
| <code>a&#124;b</code> || either term
|}


== Show an entry ==
=== <code>generate</code> (passwords) ===


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli show db.kdbx site1                   # title, username, URL, notes; password reads PROTECTED
Passwords> generate                          # 16 characters: lowercase, uppercase, digits
keepassxc-cli show -s db.kdbx site1                # -s: reveal protected values too
Passwords> generate -L 24                   # increase length to 24
keepassxc-cli show -a username db.kdbx site1       # value only, no field label
Passwords> generate --special                # enable special characters
keepassxc-cli show -a username -a password db.kdbx Internet/site1  # several attributes, one per line
Passwords> generate --exclude-similar       # avoid look-alikes such as l, 1 and I
keepassxc-cli show --all db.kdbx site1              # every attribute, custom ones included
Passwords> generate -x 'a,b,c'              # exclude individual characters
keepassxc-cli show --show-attachments db.kdbx site1 # attachment names and sizes
Passwords> generate -c 'abcdef1234'          # only from these characters
Passwords> generate --every-group            # at least one number, one uppercase letter, one lowercase letter, and a special character if enabled
</syntaxhighlight>
</syntaxhighlight>


Naming the attribute is what makes the output script-friendly:
=== <code>estimate</code> (password entropy) ===


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
PASSWORD="$(keepassxc-cli -q show -a password db.kdbx Internet/site1)"
Passwords> estimate 'some_password'    # entropy of a given password
Passwords> estimate -a 'some_password'  # -a: advanced analysis
</syntaxhighlight>
</syntaxhighlight>


<blockquote>
=== <code>diceware</code> (passphrases) ===
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.
</blockquote>
 
<blockquote>
'''<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 ==


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli clip db.kdbx site1              # password, clipboard cleared after 10 s
Passwords> diceware                  # default length: 7 words
keepassxc-cli clip -a username db.kdbx site1  # any attribute: username, url, notes, ...
Passwords> diceware -W 5            # 5 words
keepassxc-cli clip db.kdbx site1 30            # clear after 30 s instead; 0 keeps it until overwritten
Passwords> diceware -w wordlist.txt  # use custom word list
keepassxc-cli clip -b github                  # unique title match only, no group path needed
</syntaxhighlight>
</syntaxhighlight>


<blockquote>
== <code>add, edit, rm, mv</code> entries and <code>mkdir, rmdir</code> ==
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>
</blockquote>
 
== TOTP ==


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli show -t db.kdbx site1                        # the current code, and nothing else
Passwords> mkdir Internet                          # make a new group
keepassxc-cli show -a username -a password -t db.kdbx site1 # ...or after the other fields
Passwords> mkdir Internet/Sub                      # make a new subgroup: parent groups must exist
keepassxc-cli clip -t db.kdbx site1                        # copy the code to the clipboard
Passwords> add -u user1 -p Internet/site3          # create a new entry with username (-u) user1, at path Internet/site3, and prompt for password (-p)
OTP="$(keepassxc-cli -q show -t db.kdbx site1)"             # code only, for a scripted login
Passwords> add -u user1 -g -L 24 -s Internet/site3 # -g: instead of prompting for password, generate one: legnth 24, special chars included
keepassxc-cli show -a otp db.kdbx site1                    # the stored otpauth:// secret, to enrol another device
Passwords> add -u user1 -g --url https://example.com Internet/site3 # --url: for internet sites, consider specifying the login url for record
Passwords> edit -u newUser Internet/site3            # update username (-u) of entry Internet/site3 to newUser
Passwords> edit -t Mail Internet/site3             # rename the entry Internet/site3 to Mail
Passwords> edit -g Internet/site3                  # generated a new password for entry Internet/site3
Passwords> mv Internet/site3 Work                  # move an entry to another group
Passwords> rm Internet/site3                      # delete entry
Passwords> rmdir Work                              # remove a group
</syntaxhighlight>
</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.
Group = folder. Use groups to organise entries.
</blockquote>
</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>
<code>-g</code> can be coupled with the same options as the <code>generate</code> command.
</blockquote>
</blockquote>


<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.
<code>add</code> and <code>edit</code> take similar options.
</blockquote>
</blockquote>


== Add, edit, remove ==
{| class="wikitable"
! Additional option !! Effect
|-
| <code>--notes TEXT</code> || attach notes to an entry; <code>\n</code> becomes a line break
|}
 
== <code>ls</code> ==


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli add -u user1 -g db.kdbx Internet/site3          # -g: generate the password
Passwords> ls            # root group: entries, then sub-groups
keepassxc-cli add -u user1 -p db.kdbx Internet/site3          # -p: prompt for the password
Passwords> ls Internet   # one group
keepassxc-cli add -u user1 -g -L 24 -s db.kdbx Internet/site3  # generated: 24 characters, special ones included
Passwords> ls -R        # recurse into every group
keepassxc-cli add -u user1 -g --url https://example.com db.kdbx Internet/site3
Passwords> ls -f -R      # one full path per line
</syntaxhighlight>
</syntaxhighlight>
== <code>search</code> ==


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli edit -u user2 db.kdbx Internet/site3  # change one field
Passwords> search site          # entries matching a term
keepassxc-cli edit -t Mail db.kdbx Internet/site3    # rename (-t is --title here, not TOTP)
Passwords> search 'title:mail'  # field-qualified term
keepassxc-cli edit -g db.kdbx Internet/site3        # replace the password with a generated one
Passwords> search 'has:totp'    # every entry with TOTP set up
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>
'''search''' — the same query language as in the GUI search box:
{| class="wikitable"
! Syntax !! Matches
|-
| <code>title:</code>, <code>username:</code>, <code>url:</code>, <code>notes:</code>, <code>group:</code>, <code>tag:</code> || one field only; abbreviated forms work (<code>t:</code>, <code>u:</code>, <code>g:</code>, ...)
|-
| <code>has:totp</code> || entries with TOTP configured
|-
| <code>is:weak</code>, <code>is:expired</code> || weak or expired passwords
|-
| <code>!term</code> || excludes the term
|-
| <code>+term</code> || exact term only, not as a substring
|-
| <code>a&#124;b</code> || either term
|}
== <code>show</code> entries ==


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli mkdir db.kdbx Internet/Sub      # new group; parent groups must exist
Passwords> show site1                                    # show default fields
keepassxc-cli mv db.kdbx Internet/site3 Work   # move an entry to another group
Passwords> show -s Internet/site1                        # -s: reveal protected fields such as password
keepassxc-cli rmdir db.kdbx Work              # remove a group
Passwords> show -a username -a password Internet/site1   # specific attributes, one per line. use --all for all
</syntaxhighlight>
</syntaxhighlight>
{| class="wikitable"
! Additional option !! Effect
|-
| <code>--show-attachments</code> || attachment names and sizes
|}


<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:
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>.
<syntaxhighlight lang="bash" copy>
 
printf 'masterpass\nnewpass\n' | keepassxc-cli -q add -p -u user1 db.kdbx Internet/site3
<code>ls -f -R</code> prints every valid path.
</syntaxhighlight>
</blockquote>
</blockquote>


== Generate passwords ==
== <code>clip</code> to the clipboard ==
 
Replace <code>show</code> with <code>clip</code> to copy to the clipboard instead of printing to <code>stdout</code>. In general, the same options stay available


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli generate                          # 16 characters: lowercase, uppercase, digits
Passwords> clip site1              # copy the password; the clipboard is cleared after 10 s
keepassxc-cli generate -L 24 -s                 # 24 characters, special ones included
Passwords> clip -a username site1 # copy any attribute of the entry: username, url, notes, ...
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>
</syntaxhighlight>


== Database operations ==
<blockquote>
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>
 
== TOTP (<code>-t</code>) ==
 
<blockquote>
'''Caveat''': Currently, TOTP setup is a GUI-only feature in KeePassXC. <code>keepassxc-cli</code> only supports generating a TOTP from an entry already set up. A workaround to stay in the CLI is to store the oath secret key as password, then use an external TOTP generator such as <code>oathtool --totp --base32 [SECRET_KEY]</code> to generate TOTP.
</blockquote>


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli db-create -p db.kdbx                        # new database; prompts twice for its password
Passwords> show -t site1                            # show the current code
keepassxc-cli db-create -p --set-key-file keyfile db.kdbx  # password and key file as two factors
Passwords> clip -t site1                            # copy the code to the clipboard
keepassxc-cli db-info db.kdbx                              # entries, groups, encryption parameters
Passwords> show -a otp site1                        # show the stored oath secret, to enrol another device, etc.
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>
</syntaxhighlight>


<blockquote>
<blockquote>
'''<code>export</code> writes every password in clear text''' — mind where the file lands, and delete it once the import is done.
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 212:
|-
|-
| <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>
|}
|}


Line 239: Line 221:


* [https://keepassxc.org/docs/KeePassXC_UserGuide.html KeePassXC user guide] — the official guide: TOTP setup, search syntax, browser and SSH agent integration
* [https://keepassxc.org/docs/KeePassXC_UserGuide.html KeePassXC user guide] — the official guide: TOTP setup, search syntax, browser and SSH agent integration
* [https://github.com/keepassxreboot/keepassxc/blob/develop/docs/man/keepassxc-cli.1.adoc keepassxc-cli(1) man page] — every command and every option
* <code>keepassxc-cli help</code> and <code>man keepassxc-cli</code> — the same reference, offline
* <code>analyze</code> — offline Have I Been Pwned check against a downloaded password-hash list
* <code>merge</code> — merge two databases into one
* <code>attachment-import</code>, <code>attachment-export</code>, <code>attachment-rm</code> — manage file attachments
* [[Cheatsheets:LinuxCLI/ssh]] — SSH keys and <code>ssh-agent</code>, which KeePassXC can feed


[[Category:LinuxCLI]]
[[Category:LinuxCLI]]

Latest revision as of 18:40, 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 help lists every command
  • keepassxc-cli <command> -h documents one command
  • man keepassxc-cli provides a full reference

DB ops: db-create, db-info, db-edit, import, export

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 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.

open DB

Once the encrypted .kdbx is set up, open to interact with it.

keepassxc-cli open Passwords.kdbx             # will prompt for master password
keepassxc-cli -k keyfile open Passwords.kdbx  # ...if a key file is also required

This activates a command repl, eliminating the need to retype the master password for each command:

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

export and import do not work in the repl.

Every other command works in both forms:

  • Passwords> [command] inside the repl
  • keepassxc-cli [command] xxx.kdbx as standalone CLI command

Generate passwords/passphrases

generate (passwords)

Passwords> generate                          # 16 characters: lowercase, uppercase, digits
Passwords> generate -L 24                    # increase length to 24
Passwords> generate --special                # enable special characters
Passwords> generate --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 number, one uppercase letter, one lowercase letter, and a special character if enabled

estimate (password entropy)

Passwords> estimate 'some_password'     # entropy of a given password
Passwords> estimate -a 'some_password'  # -a: advanced analysis

diceware (passphrases)

Passwords> diceware                  # default length: 7 words
Passwords> diceware -W 5             # 5 words
Passwords> diceware -w wordlist.txt  # use custom word list

add, edit, rm, mv entries and mkdir, rmdir

Passwords> mkdir Internet                          # make a new group
Passwords> mkdir Internet/Sub                      # make a new subgroup: parent groups must exist
Passwords> add -u user1 -p Internet/site3          # create a new entry with username (-u) user1, at path Internet/site3, and prompt for password (-p)
Passwords> add -u user1 -g -L 24 -s Internet/site3 # -g: instead of prompting for password, generate one: legnth 24, special chars included
Passwords> add -u user1 -g --url https://example.com Internet/site3 # --url: for internet sites, consider specifying the login url for record
Passwords> edit -u newUser Internet/site3            # update username (-u) of entry Internet/site3 to newUser
Passwords> edit -t Mail Internet/site3             # rename the entry Internet/site3 to Mail
Passwords> edit -g Internet/site3                  # generated a new password for entry Internet/site3
Passwords> mv Internet/site3 Work                  # move an entry to another group
Passwords> rm Internet/site3                       # delete entry
Passwords> rmdir Work                              # remove a group

Group = folder. Use groups to organise entries.

-g can be coupled with the same options as the generate command.

add and edit take similar options.

Additional option Effect
--notes TEXT attach notes to an entry; \n becomes a line break

ls

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
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 entries

Passwords> show site1                                    # show default fields
Passwords> show -s Internet/site1                        # -s: reveal protected fields such as password
Passwords> show -a username -a password Internet/site1   # specific attributes, one per line. use --all for all
Additional option Effect
--show-attachments attachment names and sizes

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 to the clipboard

Replace show with clip to copy to the clipboard instead of printing to stdout. In general, the same options stay available

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, ...

On Linux, clip pipes to wl-copy (Wayland) or xclip (X11); without either one it fails with error All clipping programs failed.

TOTP (-t)

Caveat: Currently, TOTP setup is a GUI-only feature in KeePassXC. keepassxc-cli only supports generating a TOTP from an entry already set up. A workaround to stay in the CLI is to store the oath secret key as password, then use an external TOTP generator such as oathtool --totp --base32 [SECRET_KEY] to generate TOTP.

Passwords> show -t site1                             # show the current code
Passwords> clip -t site1                             # copy the code to the clipboard
Passwords> show -a otp site1                         # show the stored oath secret, to enrol another device, etc.

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