Intekhab Rizvi

Chapter 25 / 28

Production Deployment of HashiCorp Vault on Ubuntu LTS

HashiCorp Vault For Beginners8 min read

In the playground, we spun up Vault with a single command. In production? Not so fast.

Deploying Vault in the real world means locking it down, bootstrapping it correctly, and setting it up to survive power outages, restarts, and mistakes.

This chapter walks you through setting up HashiCorp Vault on an Ubuntu LTS server, with or without a domain name, securely and correctly.

What You’ll Learn

  • Installing Vault from the official repository
  • Difference between IP-based and domain-based access
  • Vault configuration anatomy and key files
  • Importance of memory locking (mlock)
  • File-based storage with Raft backend
  • TLS configuration
  • Managing Vault as a systemd service
  • Vault initialization, unsealing, and best practices

IP vs Domain – What Changes in Real-World Setup?

Vault is an HTTP API server at its core. It doesn’t require a domain name to run, but how you deploy it affects TLS, automation, and best practices.

CriteriaIP-Based SetupDomain-Based Setup
TLS CertificateSelf-signed or internal CAPublic CA (Let’s Encrypt, etc.)
api_addr / cluster_addrIP-based (e.g., https://10.0.0.10:8200)FQDN-based (e.g., https://vault.company.com)
Automation (CI/CD, Vault Agent)Slightly harder to manageEasier via DNS resolution
Vault UI AvailabilityWorks but browser warns about TLSSecure and smooth


You can run Vault with only an IP and a self-signed certificate. But for enterprise setups or developer convenience, it’s strongly recommended to use a fully qualified domain name (FQDN) and proper TLS.

Step 1: Install Vault (Official Binary)

Install Vault from HashiCorp’s APT repository:

sudo apt update && sudo apt install -y gnupg curl software-properties-common

curl -fsSL 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 update;
sudo apt install vault;

Step 2: Prepare Folders & TLS

Vault Folders

Vault doesn’t create its own directory structure. You must define it:

sudo mkdir -p /etc/vault.d /opt/vault/data /opt/vault/logs;
sudo chown -R vault:vault /opt/vault;
  • /etc/vault.d → All config files go here
  • /opt/vault/data → Where Vault stores secrets when using integrated Raft storage
  • /opt/vault/logs → Optional log directory if using file-based audit logs

Vault Data Folder Explained
When using the Raft storage backend, Vault persists all data—including secrets, policies, and leases—inside the data directory. It is a critical directory and must be backed up regularly using snapshot APIs.

TLS Setup

With IP (Self-Signed)

Use OpenSSL:

openssl req -x509 -nodes -days 365 \
  -newkey rsa:2048 \
  -keyout /etc/vault.d/vault.key \
  -out /etc/vault.d/vault.crt \
  -subj "/CN=<<WRITE_YOUR_IP_ADDRESS_HERE>>";

sudo chown vault:vault /etc/vault.d/vault.*;
sudo apt install certbot;
sudo certbot certonly --standalone -d <<WRITE_YOUR_FQDN_HERE>>;

Then:

sudo cp /etc/letsencrypt/live/<<WRITE_YOUR_FQDN_HERE>>/fullchain.pem /etc/vault.d/vault.crt;
sudo cp /etc/letsencrypt/live/<<WRITE_YOUR_FQDN_HERE>>/privkey.pem /etc/vault.d/vault.key;
sudo chown vault:vault /etc/vault.d/vault.*;

Step 3: Vault Configuration Explained

Create a file at /etc/vault.d/vault.hcl:

ui = true
log_level = "info"

storage "raft" {
  path    = "/opt/vault/data"
  node_id = "vault-node-1"
}

listener "tcp" {
  address       = "0.0.0.0:8200"
  tls_cert_file = "/etc/vault.d/vault.crt"
  tls_key_file  = "/etc/vault.d/vault.key"
}

api_addr = "https://<<YOUR_IP_OR_FQDN_HERE>>:8200"
cluster_addr = "https://<<YOUR_IP_OR_FQDN_HERE>>:8201"

disable_mlock = false

Breakdown of Key Config Items:

KeyDescription
ui = trueEnables Vault’s browser interface
storage "raft"Uses Raft for HA-ready local storage
node_idUnique name of this Vault node
listenerDefines network interface and TLS settings
api_addrHow clients communicate with Vault (must match cert)
cluster_addrUsed for internal cluster gossip
disable_mlockSet to false in production; read below

About mlock (Memory Lock)

Vault uses in-memory encryption and holds sensitive data in RAM. Linux swaps out memory pages to disk under pressure, which is a security nightmare for secrets.

The mlock syscall prevents memory from being swapped.

What Happens If You Don’t Use mlock?

  • Vault will log a warning
  • Secrets in memory could end up in disk swap
  • Regulatory compliance may be violated

Step 4: Create Vault systemd Unit

Create /etc/systemd/system/vault.service:

[Unit]
Description=HashiCorp Vault
Requires=network-online.target
After=network-online.target

[Service]
User=vault
Group=vault
ProtectSystem=full
ProtectHome=read-only
PrivateTmp=yes
Capabilities=CAP_IPC_LOCK
CapabilityBoundingSet=CAP_IPC_LOCK
ExecStart=/usr/bin/vault server -config=/etc/vault.d/vault.hcl
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
LimitMEMLOCK=infinity
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

Then reload and start Vault:

sudo systemctl daemon-reexec;
sudo systemctl enable vault;
sudo systemctl start vault;

Step 5: Initialize and Unseal Vault

First, set the address (replace with your IP or domain):

export VAULT_ADDR=https://<<YOUR_IP_OR_FQDN_HERE>>:8200;
export VAULT_CACERT=/etc/vault.d/vault.crt

Initialize Vault:

vault operator init -key-shares=5 -key-threshold=3 > ~/vault.init

Unseal Vault (you need 3 keys out of 5):

vault operator unseal <key1>
vault operator unseal <key2>
vault operator unseal <key3>

Step 6: Security and Hardening Checklist

MeasureDescription
TLS EverywhereNever run Vault without TLS, even locally
Memory LockPrevent secrets from hitting disk swap
FirewallBlock everything except port 8200 (and 443 if reverse proxy)
Audit LoggingEnable file-based audit logging
Secrets BackupsUse Raft snapshot API regularly
Limited RootAvoid running Vault CLI with root privileges
Cert RenewalAutomate TLS cert renewals via cron or timer

Final Validation

If everything went well, visiting:

https://<<YOUR_IP_OR_FQDN_HERE>>:8200

Should show you the Vault UI.

Recap

In this chapter, you learned how to:

  • Deploy Vault on an Ubuntu LTS server with Raft storage
  • Secure it using TLS and memory locking
  • Understand the Vault folder structure and key config parameters
  • Run it as a production-grade service using systemd
  • Work with both IP-based and domain-based setups

You now have a Vault server that’s reliable, secure, and production-ready.