Table of Contents
- Overview of Auth Methods
- 1. Authenticating with an Existing Token
- 2. Authenticating with Userpass
- 3. Token Helper & Caching
- 4. Machine-Friendly JSON Authentication (AppRole)
- Next Steps
- References
Overview of Auth Methods
| Auth Method | CLI Usage | Description |
|---|---|---|
| Token | vault login <token> | Authenticate with a pre-generated Vault token |
| Userpass | vault login -method=userpass username=<user> | Username/password authentication |
| AppRole | vault write auth/approle/login ... | Machine-to-machine auth for automation |
| OIDC | vault login -method=oidc | Single Sign-On via OIDC providers |
1. Authenticating with an Existing Token
If you already have a Vault token, simply run: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: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 successfulvault login, the CLI writes your token to ~/.vault-token. This token helper:
- Stores your token so you don’t have to re-enter it for every command
- 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:export VAULT_FORMAT=json
Instructs the Vault CLI to return JSON.vault write auth/approle/login ...
Authenticates via AppRole and captures the full JSON response inOUTPUT.jq -r '.auth.client_token'
Extracts the client token.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