Cheatsheets:Keepassxc-cli: Difference between revisions

From Wikibase
Jump to navigation Jump to search
No edit summary
 
(4 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 can open, read and edit the same encrypted <code>.kdbx</code> databases just like the desktop application to manage your secrets
<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 9: Line 9:
* <code>man keepassxc-cli</code> provides a full reference
* <code>man keepassxc-cli</code> provides a full reference


== DB ops ==
== DB ops: <code>db-create, db-info, db-edit, import, export</code> ==


KeePassXC store all your secrets in encrypted <code>.kdbx</code> files.
KeePassXC stores all your secrets in encrypted <code>.kdbx</code> files.


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
Line 31: Line 31:
</blockquote>
</blockquote>


== Keepassxc-cli repl ==
== <code>open</code> DB ==


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.
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 Passwords.kdbx     # enter a keepassxc-cli repl on Passwords.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
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 45: Line 47:
Passwords&gt; clip -t Internet/site1
Passwords&gt; clip -t Internet/site1
Passwords&gt; close                  # close the current database, stay in the repl
Passwords&gt; close                  # close the current database, stay in the repl
Passwords&gt; exit                    # exist repl
Passwords&gt; 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&gt; [command]</code> inside the repl
* <code>keepassxc-cli [command] xxx.kdbx</code> as standalone CLI command
</blockquote>
</blockquote>


<!-- all following sections should be rewritten as commands inside the repl when possible: e.g., keepassxc-cli ls db.kdbx becomes Passwords&gt; ls-->
== Generate passwords/passphrases ==
== Edit secrets ==


<!-- use option tables in this section, as the command structures and options for add/edit are extremely similar-->
=== <code>generate</code> (passwords) ===


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli add -u user1 -g db.kdbx Internet/site3          # -g: generate the password
Passwords> generate                          # 16 characters: lowercase, uppercase, digits
keepassxc-cli add -u user1 -p db.kdbx Internet/site3          # -p: prompt for the password
Passwords> generate -L 24                    # increase length to 24
keepassxc-cli add -u user1 -g -L 24 -s db.kdbx Internet/site3  # generated: 24 characters, special ones included
Passwords> generate --special                # enable special characters
keepassxc-cli add -u user1 -g --url https://example.com db.kdbx Internet/site3
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
</syntaxhighlight>
</syntaxhighlight>
=== <code>estimate</code> (password entropy) ===


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli edit -u user2 db.kdbx Internet/site3  # change one field
Passwords> estimate 'some_password'    # entropy of a given password
keepassxc-cli edit -t Mail db.kdbx Internet/site3    # rename (-t is --title here, not TOTP)
Passwords> estimate -a 'some_password'  # -a: advanced analysis
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>
=== <code>diceware</code> (passphrases) ===


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli mkdir db.kdbx Internet/Sub      # new group; parent groups must exist
Passwords> diceware                  # default length: 7 words
keepassxc-cli mv db.kdbx Internet/site3 Work  # move an entry to another group
Passwords> diceware -W 5            # 5 words
keepassxc-cli rmdir db.kdbx Work              # remove a group
Passwords> diceware -w wordlist.txt  # use custom word list
</syntaxhighlight>
</syntaxhighlight>


<blockquote>
== <code>add, edit, rm, mv</code> entries and <code>mkdir, rmdir</code> ==
<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>
<syntaxhighlight lang="bash" copy>
printf 'masterpass\nnewpass\n' | keepassxc-cli -q add -p -u user1 db.kdbx Internet/site3
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
</syntaxhighlight>
</syntaxhighlight>
<blockquote>
Group = folder. Use groups to organise entries.
</blockquote>
</blockquote>


== Generate passwords ==
<blockquote>
<code>-g</code> can be coupled with the same options as the <code>generate</code> command.
</blockquote>


<syntaxhighlight lang="bash" copy>
<blockquote>
keepassxc-cli generate                          # 16 characters: lowercase, uppercase, digits
<code>add</code> and <code>edit</code> take similar options.
keepassxc-cli generate -L 24 -s                # 24 characters, special ones included
</blockquote>
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 -->
{| class="wikitable"
! Additional option !! Effect
|-
| <code>--notes TEXT</code> || attach notes to an entry; <code>\n</code> becomes a line break
|}


== List ==
== <code>ls</code> ==


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli ls db.kdbx                  # root group: entries, then sub-groups
Passwords> ls           # root group: entries, then sub-groups
keepassxc-cli ls db.kdbx Internet         # one group
Passwords> ls Internet   # one group
keepassxc-cli ls -R db.kdbx                # recurse into every group
Passwords> ls -R         # recurse into every group
keepassxc-cli ls -f -R db.kdbx            # -f: flatten, one full path per line
Passwords> ls -f -R     # one full path per line
</syntaxhighlight>
</syntaxhighlight>


<!-- use an options table instead for ls -f and -R-->
== <code>search</code> ==
 
== Search ==


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli search db.kdbx site          # entries matching a term
Passwords> search site          # entries matching a term
keepassxc-cli search db.kdbx 'title:mail'  # field-qualified term
Passwords> search 'title:mail'  # field-qualified term
keepassxc-cli search db.kdbx 'has:totp'    # every entry with TOTP set up
Passwords> search 'has:totp'    # every entry with TOTP set up
</syntaxhighlight>
</syntaxhighlight>


the same query language as in the GUI search box:
'''search''' — the same query language as in the GUI search box:


{| class="wikitable"
{| class="wikitable"
Line 141: Line 157:
|}
|}


== Show an entry ==
== <code>show</code> entries ==


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli show db.kdbx site1                   # -s: reveal protected values too
Passwords> show site1                                    # show default fields
keepassxc-cli show -a username -a password db.kdbx Internet/site1  # show specific attributes, one per line
Passwords> show -s Internet/site1                       # -s: reveal protected fields such as password
keepassxc-cli show --all db.kdbx site1              # every attribute, custom ones included
Passwords> show -a username -a password Internet/site1  # specific attributes, one per line. use --all for all
keepassxc-cli show --show-attachments db.kdbx site1 # attachment names and sizes
</syntaxhighlight>
</syntaxhighlight>


<!-- use an options table instead for --all, --show-attachments -->
{| class="wikitable"
 
! Additional option !! Effect
Naming the attribute is what makes the output script-friendly:
|-
 
| <code>--show-attachments</code> || attachment names and sizes
<syntaxhighlight lang="bash" copy>
|}
PASSWORD="$(keepassxc-cli -q show -a password db.kdbx Internet/site1)"
</syntaxhighlight>


<blockquote>
<blockquote>
Line 164: Line 177:
</blockquote>
</blockquote>


== Clip: Copy to the clipboard ==
== <code>clip</code> to the clipboard ==


Replace <code>show</code> with <code>clip</code> to copy to clipboard instead of printing to <code>stout</code>.
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 clip db.kdbx site1               # copy password of the entry to the clipboard. clipboard will be cleared after 10 s
Passwords> clip site1             # copy the password; the clipboard is cleared after 10 s
keepassxc-cli clip -a username db.kdbx site1   # copy any attribute of the entry: username, url, notes, ...
Passwords> clip -a username site1 # copy any attribute of the entry: username, url, notes, ...
keepassxc-cli clip -t db.kdbx site1            # copy current totp code to system clipboard
</syntaxhighlight>
</syntaxhighlight>


Line 178: Line 190:
</blockquote>
</blockquote>


== TOTP ==
== TOTP (<code>-t</code>) ==


<blockquote>
<blockquote>
'''Caveat''': <code>keepassxc-cli</code> currently only supports generating TOTP from an entry already setup. The setup must be done in GUI.
'''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>
</blockquote>


<syntaxhighlight lang="bash" copy>
<syntaxhighlight lang="bash" copy>
keepassxc-cli show -t db.kdbx site1                         # show the current code
Passwords> show -t site1                             # show the current code
OTP="$(keepassxc-cli -q show -t db.kdbx site1)"            # code only, for a scripted login
Passwords> clip -t site1                             # copy the code to the clipboard
keepassxc-cli show -a otp db.kdbx site1                     # the stored otpauth:// secret, to enrol another device
Passwords> show -a otp site1                         # show the stored oath secret, to enrol another device, etc.
</syntaxhighlight>
</syntaxhighlight>


Line 209: 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

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