Skip to main content
In this guide, you’ll learn how to authenticate to HashiCorp Vault using the CLI. Once you’ve enabled an auth method (e.g., Token, Userpass, OIDC, AppRole), you can log in and cache your client token for seamless future requests.

Table of Contents

  1. Overview of Auth Methods
  2. 1. Authenticating with an Existing Token
  3. 2. Authenticating with Userpass
  4. 3. Token Helper & Caching
  5. 4. Machine-Friendly JSON Authentication (AppRole)
  6. Next Steps
  7. References

Overview of Auth Methods


1. Authenticating with an Existing Token

If you already have a Vault token, simply run:
Example output:
By default, vault login uses the token auth method and caches your token for subsequent commands.

2. Authenticating with Userpass

Use the userpass auth method when you don’t have a token but have Vault credentials:
After providing the correct password, you’ll see:

Command Breakdown

  • vault login
    The Vault CLI subcommand for authentication.
  • -method=userpass
    Selects the Userpass auth method.
  • username=bryan
    Supplies the required username parameter.
If you have multiple mounts of the same auth type, add -path=<mount_path> to specify the correct one.

3. Token Helper & Caching

After a successful vault login, the CLI writes your token to ~/.vault-token. This token helper:
  1. Stores your token so you don’t have to re-enter it for every command
  2. Automatically reads and attaches the token to subsequent API calls
Keep ~/.vault-token secure. Anyone with access can perform Vault operations under your identity.

4. Machine-Friendly JSON Authentication (AppRole)

For CI/CD pipelines or automation, request JSON output and parse the token:
Steps Explained:
  1. export VAULT_FORMAT=json
    Instructs the Vault CLI to return JSON.
  2. vault write auth/approle/login ...
    Authenticates via AppRole and captures the full JSON response in OUTPUT.
  3. jq -r '.auth.client_token'
    Extracts the client token.
  4. vault login "$VAULT_TOKEN"
    Caches the token for subsequent CLI calls.

Next Steps

Now that you’ve authenticated:
  • Read secrets: vault kv get secret/my-app/config
  • Write secrets: vault kv put secret/my-app/config key=value
  • Renew tokens: vault token renew
Explore more in the Vault CLI documentation.

References

Watch Video