2020-04-07 18:55:19 +00:00
---
2020-09-01 15:14:13 +00:00
layout: commands
2020-04-07 18:55:19 +00:00
page_title: 'Commands: ACL Set Agent Token'
2023-01-26 18:42:13 +00:00
description: >-
The `consul acl set-agent-token` command updates an agent's ACL tokens to introduce the agent ACL tokens for the first time or to update tokens.
2020-04-07 18:55:19 +00:00
---
# Consul ACL Set Agent Token
Command: `consul acl set-agent-token`
2023-01-25 16:52:43 +00:00
Corresponding HTTP API Endpoint: [\[PUT\] /v1/agent/token/:type](/consul/api-docs/agent#update-acl-tokens)
2022-01-10 17:40:11 +00:00
2020-04-07 18:55:19 +00:00
This command updates the ACL tokens currently in use by the agent. It can be used to introduce
ACL tokens to the agent for the first time, or to update tokens that were initially loaded from
2021-05-31 23:05:47 +00:00
the agent's configuration. Tokens are not persisted unless
2023-01-25 16:52:43 +00:00
[`acl.enable_token_persistence`](/consul/docs/agent/config/config-files#acl_enable_token_persistence)
2021-05-31 23:05:47 +00:00
is `true`, so tokens will need to be updated again if that option is `false` and
the agent is restarted.
2020-04-07 18:55:19 +00:00
2023-01-25 16:52:43 +00:00
The table below shows this command's [required ACLs](/consul/api-docs/api-structure#authentication). Configuration of
[blocking queries](/consul/api-docs/features/blocking) and [agent caching](/consul/api-docs/features/caching)
2022-01-10 21:44:56 +00:00
are not supported from commands, but may be from the corresponding HTTP endpoint.
| ACL Required |
| ------------ |
| `acl:write` |
2020-04-07 18:55:19 +00:00
## Usage
2022-07-27 06:17:11 +00:00
Usage: `consul acl set-agent-token [options] token_type token_secret_id`
2020-04-07 18:55:19 +00:00
2022-07-27 06:17:11 +00:00
The token types are:
2020-04-07 18:55:19 +00:00
- `agent` - The token that the agent will use for internal agent operations.
If not given then the default token is used for these operations.
2023-11-13 19:51:49 +00:00
- `dns` - Specifies the token that agents use to request information needed to respond to DNS queries.
If the `dns` token is not set, Consul uses the `default` token by default.
Because the `default` token allows unauthenticated HTTP API access to list nodes and services, we
strongly recommend using the `dns` token. Create DNS tokens using the [templated policy](/consul/docs/security/acl/tokens/create/create-a-dns-token#create_a_dns_token) option
to ensure that the token has the permissions needed to respond to all DNS queries.
2020-04-07 18:55:19 +00:00
2023-01-10 16:24:02 +00:00
- `config_file_service_registration` - This is the token that the agent uses to
register services and checks defined in config files. This token needs to be
configured with write permissions for the services or checks being registered.
If not set, the `default` token is used. If a service or check definition
contains a `token` field, then that token is used to register that service or
check instead of the `config_file_service_registration` token.
2023-11-13 19:51:49 +00:00
- `replication` - This is the token that the agent uses for replication
operations. This token must be configured with read access to
all data that the agent replicates.
- `recovery` - This sets the token that allows access to the agent APIs when the ACL datacenter is unreachable.
- `default` - The default token is the token that the agent uses for
both internal agent operations and operations initiated by the HTTP
and DNS interfaces when no specific token is provided. If not set the
agent uses the anonymous token.
2020-04-07 18:55:19 +00:00
### API Options
@include 'http_api_options_client.mdx'
2020-04-07 23:56:08 +00:00
2020-04-07 18:55:19 +00:00
@include 'http_api_options_server.mdx'
## Examples
Set the `default` token:
2020-05-19 18:32:38 +00:00
```shell-session
2020-04-07 18:55:19 +00:00
$ consul acl set-agent-token default c4d0f8df-3aba-4ab6-a7a0-35b760dc29a1
```