The “doctl auth” command is a part of the “doctl” CLI tool provided by DigitalOcean. It allows you to authenticate the doctl CLI tool with one or more API tokens, which are used for authenticating and authorizing your interactions with the DigitalOcean API.
Here are some key functionalities and subcommands of “doctl auth”:
- “doctl auth init“: This subcommand initializes the authentication process. It prompts you to enter your DigitalOcean API token, which is a unique identifier that grants access to your DigitalOcean resources. Once you provide the token, it is securely stored locally on your system for future use.
- “doctl auth list“: With this subcommand, you can view a list of the API tokens that are currently configured in your doctl tool. It displays details such as the token name and the associated token ID. This command helps you manage and keep track of multiple API tokens if you have them.
- “doctl auth switch“: This subcommand allows you to switch between different API tokens. If you have multiple tokens configured, this command lets you choose the token you want to use for a particular session or interaction. It provides flexibility when working with different DigitalOcean accounts or projects.
- “doctl auth rm“: This subcommand enables you to remove an API token from your doctl tool. It deletes the specified token from your local configuration, ensuring that it can no longer be used for authentication.
- “doctl auth whoami“: With this subcommand, you can retrieve information about the currently authenticated account. It displays details such as the account’s email address, UUID, and username. This command is helpful for quickly confirming the identity of the account associated with the currently active API token.
Authentication with API tokens is crucial for securely accessing and managing your DigitalOcean resources through the CLI. The “doctl auth” command provides a set of subcommands to initialize, manage, and switch between API tokens. It allows you to authenticate doctl with your DigitalOcean account, granting you the necessary privileges to interact with the DigitalOcean API and perform various operations on your resources.
doctl auth Command Examples
1. Open a prompt to enter an API token and label its context:
# doctl auth init --context token_label
2. List authentication contexts (API tokens):
# doctl auth list
3. Switch contexts (API tokens):
# doctl auth switch --context token_label
4. Remove a stored authentication context (API token):
# doctl auth remove --context token_label
5. Show available commands:
# doctl auth --help