This guide walks you through installing and configuring HashiCorp Vault on your own VPS, giving you a centralized secrets management system for API keys, database credentials, and other sensitive data. You’ll end up with a working Vault server using the filesystem storage backend, TLS enabled, and a basic understanding of how to store and retrieve secrets. Before starting, you need a VPS with Ubuntu 22.04 or 24.04, root access, and a domain name pointing to the server’s IP address.
What You’ll Need
- A VPS with at least 1 GB RAM and 10 GB disk space (Ubuntu 22.04/24.04 recommended)
- Root or sudo access to the server
- A domain name (or subdomain) pointing to your VPS’s public IP address (for TLS)
- Basic familiarity with the command line and systemd
Step-by-Step
- Update the system and install prerequisites. SSH into your VPS and run
sudo apt update && sudo apt upgrade -y. Then install required tools:sudo apt install -y curl unzip gnupg lsb-release. - Install Vault. Download the official Vault binary from HashiCorp’s releases page. For the latest version (check
https://releases.hashicorp.com/vault/), usewget https://releases.hashicorp.com/vault/1.17.6/vault_1.17.6_linux_amd64.zip(replace version if newer). Unzip it, move the binary to/usr/local/bin/, and verify withvault --version. - Create a dedicated system user. Run
sudo useradd --system --home /etc/vault --shell /bin/false vaultto create a non-login user for Vault. - Create the configuration directory and file. Create
/etc/vaultwithsudo mkdir -p /etc/vault. Then create/etc/vault/vault.hclwith the following content (adjustapi_addrto your domain):storage "file" {
path = "/opt/vault/data"
}
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file = "/etc/vault/tls/vault.crt"
tls_key_file = "/etc/vault/tls/vault.key"
}
api_addr = "https://vault.example.com:8200"
ui = true
disable_mlock = true
Note:disable_mlockis set to true for simplicity; in production, consider removing it and granting the vault user the ability to mlock (seesetcap cap_ipc_lock=+ep /usr/local/bin/vault). - Create the data directory. Run
sudo mkdir -p /opt/vault/dataand set ownership:sudo chown -R vault:vault /opt/vault /etc/vault. - Set up TLS certificates. For a production setup, use Let’s Encrypt with certbot:
sudo apt install certbotand obtain a certificate for your domain:sudo certbot certonly --standalone -d vault.example.com. Then copy the cert and key to/etc/vault/tls/and set permissions:sudo mkdir -p /etc/vault/tls && sudo cp /etc/letsencrypt/live/vault.example.com/fullchain.pem /etc/vault/tls/vault.crt && sudo cp /etc/letsencrypt/live/vault.example.com/privkey.pem /etc/vault/tls/vault.key && sudo chown -R vault:vault /etc/vault/tls. - Create a systemd service file. Create
/etc/systemd/system/vault.servicewith:[Unit]
Description=HashiCorp Vault
After=network.target[Service]
User=vault
Group=vault
ExecStart=/usr/local/bin/vault server -config=/etc/vault/vault.hcl
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=on-failure
LimitNOFILE=65536[Install]
WantedBy=multi-user.target - Start and enable Vault. Run
sudo systemctl daemon-reload, thensudo systemctl start vaultandsudo systemctl enable vault. Check status withsudo systemctl status vault. - Initialize Vault. Set the environment variable
export VAULT_ADDR='https://vault.example.com:8200'. Then runvault operator init -key-shares=1 -key-threshold=1(for testing; use 5 and 3 in production). Save the unseal key and root token securely. Vault is now initialized but sealed. - Unseal Vault. Run
vault operator unsealand enter the unseal key when prompted. Repeat if you used multiple key shares. After unsealing, log in withvault loginand the root token. - Enable a secrets engine and store a test secret. Run
vault secrets enable -path=secret kv-v2(for KV v2). Then store a secret:vault kv put secret/myapp password=supersecret. Retrieve it withvault kv get secret/myapp. - Access the UI (optional). Navigate to
https://vault.example.com:8200/uiin your browser, log in with the root token, and manage secrets visually.
Common Mistakes
- Forgetting to unseal after reboot. Vault seals on restart; you must unseal manually or use an auto-unseal mechanism like cloud KMS or a separate unseal service.
- Using the root token in production. Root tokens are powerful; create a policy with least privilege and use that for daily operations.
- Exposing Vault to the public internet without TLS. Always use TLS. Vault sends secrets in plaintext if not.
- Setting
disable_mlockwithout understanding the risk. In production, mlock prevents memory swapping; disabling it can expose secrets in swap. Usesetcapinstead. - Using a weak unseal key threshold. A single key share is convenient but insecure. Use at least 3 shares and a threshold of 2.
Tips
- Back up your unseal keys and root token. Store them in a password manager or offline. Losing them means losing access to all secrets.
- Use a dedicated VPS for Vault. Don’t run other services on the same server to reduce attack surface.
- Enable audit logging. Run
vault audit enable file file_path=/var/log/vault_audit.logto track access. - Use dynamic secrets where possible. For databases, enable the database secrets engine to generate short-lived credentials instead of static ones.
- Set up a backup routine. Backup the
/opt/vault/datadirectory and the unseal keys. Test restores.
Troubleshooting
- Vault service fails to start. Check logs with
sudo journalctl -u vault -f. Common issues: permissions on config/data directories, invalid config syntax, or missing TLS files. - Cannot connect to Vault. Check if the port 8200 is open:
sudo ufw statusorss -tulpn | grep 8200. Ensure your VPS firewall allows it. Also verifyVAULT_ADDRis set correctly. - TLS errors in browser. Ensure your certificate is valid and not expired. Use
curl -v https://vault.example.com:8200/v1/sys/healthto test. - Vault is sealed after restart. Run
vault operator unsealagain. Consider setting up auto-unseal if this is frequent. - Permission denied when reading secrets. Check your token’s policy:
vault token capabilities. Create a policy that grants read on the path you need.
Frequently Asked Questions
Q: Can I use Vault without TLS if it’s behind a VPN?
A: Technically yes, but it’s risky. If the VPN is compromised, secrets are exposed. Always use TLS even in private networks.
Q: What is the difference between KV v1 and KV v2?
A: KV v2 supports versioning and metadata, allowing you to roll back to previous secret values. KV v1 is simpler but overwrites on write.
Q: How do I rotate the root token?
A: Run vault token create -policy=root -ttl=1h to create a temporary root token, then revoke the original. Or use vault operator generate-root with unseal keys.
Q: Can I use Vault for SSH key management?
A: Yes, Vault has an SSH secrets engine that can generate one-time SSH passwords or sign SSH keys.
Q: How do I upgrade Vault?
A: Download the new binary, replace the old one, and restart the service. Always back up data and unseal keys before upgrading.
Q: What happens if I lose all unseal keys?
A: You lose access to all secrets. There is no recovery. This is why backing up keys is critical.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Valheim Server Not Showing in Community List Fixes
- DisplayPort vs HDMI: Which Cable Should You Use?
- Soundbar vs 2.1 Speaker System: Which Is Better?
- Survive Lava for Brainrot Tier List170 points
- MySQL Dump Import: Fix Common Errors
- Mouse Moving on Its Own? Causes & Fixes