Skip to main content
In this guide, you’ll learn how to manage secrets with Vault’s Key/Value (KV) Secrets Engine using the vault kv CLI. We’ll cover KV version 1 and version 2 operations:
  • Core commands: put, get, delete, list
  • KV V2–only versioning commands: undelete, destroy, patch, rollback
Master these commands to automate secrets management in scripts and CI/CD pipelines.

KV CLI Command Overview

Use vault kv <subcommand> to perform KV operations. The table below summarizes each subcommand:
The image is a guide on using the vault kv command in the CLI, detailing various operations like put, get, delete, and list, with additional commands available for KV V2.

Writing Data with vault kv put

Use vault kv put to store or update secrets. The syntax is:
  • <mount-path>/<secret-path>: The mount and path for your secret
  • key=value: Each key/value pair becomes a field in the secret

KV Version 1 vs. Version 2

KV V1 Example

KV V2 Example

On KV V2, put returns extra metadata (creation time, deletion time, destroyed flag, and version).

Writing Multiple Pairs or JSON Files

Inline multiple pairs:
You can also read key/value pairs from a JSON file:
secrets.json example:

Reading Data with vault kv get

Retrieve secrets in table or JSON format.

Table Output

KV V1

KV V2

JSON Output for Automation

Pipe to jq for CI/CD automation:

Reading Specific Versions (KV V2)

  • Default (latest): vault kv get kv/app/db
  • Specific: vault kv get -version=3 kv/app/db
If the latest version is soft‐deleted, only metadata is returned.

Updating Secrets

Overwrite with put

A full put replaces all fields:
Existing fields are lost; only the new api remains in version 2.

Revert Changes with rollback (KV V2)

This creates version 3 with data from version 1.

Merge Fields with patch (KV V2)

patch adds or updates fields without removing existing data.

Deleting Secrets

The image explains the process of deleting secrets from a KV store, detailing the differences between delete actions in KV V1 and KV V2, and the concept of a destroy action in KV V2. It highlights the permanence and recoverability of data in each scenario.

Soft Delete with delete

  • KV V1: Permanently removes data
  • KV V2: Marks the latest version as deleted (soft delete)

After Delete

KV V1:
KV V2:

Permanent Removal with destroy (KV V2)

destroy permanently deletes specified versions. This action cannot be undone.

Remove All Versions and Metadata


You’ve now mastered the KV Secrets Engine CLI operations for both KV V1 and KV V2. Next up: exploring the Transit Secrets Engine for encryption-as-a-service.

Watch Video