| Method | Usage Scope | Example |
|---|---|---|
| Environment Variable | Entire shell session | export CONSUL_HTTP_TOKEN=YOUR_TOKEN |
| Token-File Environment Variable | Entire shell session | export CONSUL_HTTP_TOKEN_FILE=/path/to/token.txt |
--token Command-Line Flag | Single command | consul members --token YOUR_TOKEN |
--token-file Command-Line Flag | Single command | consul members --token-file /path/to/token.txt |
1. Export an Environment Variable
Supply the ACL token once per session. All subsequent Consul commands will automatically pick it up:Storing tokens as environment variables is convenient, but ensure your shell history is secured to prevent accidental leakage.
2. Export a Token-File Environment Variable
If you prefer keeping tokens out of your shell history, you can point to a file that contains the token:chmod 600) to protect sensitive data.
3. Use the --token Flag
For one-off commands, specify the token inline. This overrides any environment variable settings:
4. Use the --token-file Flag
Combine the security of a file with the precision of a per-command setting:
The
--token-file flag instructs Consul to read the token from the specified path, mirroring the behavior of CONSUL_HTTP_TOKEN_FILE.