Database passwords in a .env file, API keys pasted into CI variables, SSH keys shared over chat: most teams store secrets in places that were never designed to protect them. HashiCorp Vault is a dedicated system for storing, controlling, and auditing access to secrets. This HashiCorp Vault tutorial takes you from installation to storing your first secrets, writing access policies, and generating short-lived dynamic credentials.
What Vault Solves – HashiCorp Vault Tutorial
- Central storage with encryption: secrets live in one audited place instead of scattered config files.
- Fine-grained policies: each application or person receives access only to the paths they need.
- Dynamic secrets: instead of static passwords, Vault can generate credentials on demand that expire automatically, for example database users that live for one hour.
- Complete audit log: every read and write is recorded, so you can answer “who accessed this secret, and when?”
- Sealing: Vault starts sealed and must be unsealed with key shares before any secret can be read, which protects data at rest.
Prerequisites – HashiCorp Vault Tutorial
- A Linux server (this guide uses Ubuntu) with sudo access.
- Basic command-line skills. Development mode runs entirely on one machine, so no other infrastructure is required to learn.
Step 1: Install Vault
Vault ships from the same HashiCorp APT repository used for Terraform:
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt-get update && sudo apt-get install -y vault
vault --version
Step 2: Start a Development Server
Dev mode starts an in-memory, already-unsealed Vault that is perfect for learning. Never use it in production, because all data vanishes on restart:
vault server -dev
The output prints a Root Token. In a second terminal, point the CLI at the server and log in:
export VAULT_ADDR="http://127.0.0.1:8200"
vault login <ROOT_TOKEN>
vault status
vault status should report Sealed: false. Every HashiCorp Vault tutorial starts here for a reason: with one command you have the full API available to experiment against safely.
Step 3: Store and Read KV Secrets
Dev mode pre-mounts a key-value engine at secret/. Store a secret, read it back, and list versions:
vault kv put -mount=secret myapp/config username="app_user" password="S3cure!Pass"
vault kv get -mount=secret myapp/config
vault kv get -mount=secret -format=json myapp/config
The KV v2 engine versions every write, so you can roll back: vault kv rollback -mount=secret -version=1 myapp/config. Notice that the CLI never shows other versions’ values unless you ask, and applications fetch exactly the same data over the HTTP API with a token in the X-Vault-Token header.

Step 4: Control Access with Policies
Policies are HCL documents that grant capabilities on paths. Create myapp-policy.hcl:
path "secret/data/myapp/*" {
capabilities = ["read", "list"]
}
path "secret/metadata/myapp/*" {
capabilities = ["list"]
}
Load it, then create a token bound to it:
vault policy write myapp myapp-policy.hcl
vault token create -policy="myapp" -ttl="24h"
Log in with the new token (vault login <TOKEN>) and test: reading secret/myapp/config succeeds, while writing to it or reading any other path is denied. In real deployments, applications authenticate with methods such as AppRole or the Kubernetes auth method instead of hand-created tokens, but the policy model stays exactly the same.
Step 5: Generate Dynamic Database Secrets
Static passwords live forever; dynamic secrets are created per request and expire. With a database engine configured, an application asks Vault for credentials and receives a brand-new database user:
vault secrets enable database
vault write database/config/mydb \
plugin_name=mysql-database-plugin \
connection_url="{{username}}:{{password}}@tcp(127.0.0.1:3306)/" \
allowed_roles="app-role" \
username="vault-admin" \
password="admin-password"
vault write database/roles/app-role \
db_name=mydb \
creation_statements="CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}'; GRANT SELECT ON app.* TO '{{name}}'@'%';" \
default_ttl="1h" \
max_ttl="24h"
vault read database/creds/app-role
Each read returns a unique username, password, and lease ID. When the lease expires, Vault deletes the database user automatically. Even if a credential leaks, it dies within the hour. This capability is the strongest argument in any HashiCorp Vault tutorial for moving beyond static secrets.
Troubleshooting Common Problems
Vault is sealed after a restart
That is by design. A production server needs vault operator unseal with the required number of key shares (or an auto-unseal mechanism such as a cloud KMS). Dev servers simply need to be restarted and re-populated.
Permission denied reading a KV v2 secret
KV v2 paths in policies include /data/ for values and /metadata/ for listing. A policy written for KV v1 style paths (secret/myapp/*) will not match. Check the engine version with vault secrets list -detailed.
Client requests fail with connection errors
Confirm VAULT_ADDR matches the listener address and scheme (http vs https). Most beginner issues in this HashiCorp Vault tutorial trace back to a forgotten export in a new terminal.
Moving from Dev Mode Toward Production
A production Vault differs from the dev server in four ways. First, it uses persistent storage; the integrated Raft storage is the standard choice and removes the need for a separate database cluster. Second, it serves TLS, because tokens and secrets must never cross the network in plaintext. Third, unsealing is a deliberate process: either operators enter Shamir key shares after each restart, or you configure auto-unseal with a cloud KMS or HSM so restarts are hands-free while keys stay protected. Fourth, enable the audit device immediately (vault audit enable file file_path=/var/log/vault-audit.log) so every interaction is recorded from day one. Also create a break-glass procedure, revoke the initial root token after setup in favor of personal admin tokens, and snapshot Raft storage regularly with vault operator raft snapshot save. Treat Vault like the crown jewels it guards: its availability and integrity define the security of everything that depends on it.
Conclusion
This HashiCorp Vault tutorial covered the essentials: installing Vault, running a dev server, storing versioned KV secrets, restricting access with policies, and issuing dynamic database credentials with automatic expiry. For production, plan your unseal strategy, enable the audit device, and use integrated (Raft) storage with TLS. Complement Vault with the hardening basics in our Fail2Ban SSH protection guide, and explore engines, auth methods, and the API in the HashiCorp Vault official documentation.